how to launch an activity with 'sartActivityForResult' from an ItemizedOverlay class

104 views Asked by At

I have this scenario:

  • Main activity with one button. Once clicked it launchs 'mapActivity'
  • Map activity (extending MapActivity) uses an ItemizedOverlay (extending ItemizedOverlay) class to mark places over the map.

Now, I want to launch another activity from my itemized overlay. I achieved to launch one activity as standar intent this way:

@Override
public boolean onTap(GeoPoint point, MapView mapView) {

     boolean tapped = super.onTap(point, mapView);

    if (!tapped){           
        Intent intent = new Intent();
        intent.setClass(this.context, EditarLugarActivity.class);
        this.context.startActivity (intent);
    return true;
}

EditarLugarActivity is an activity whichs obtain a text input from user. Now, I need to get that text from the Itemized Overlay activity. Context have the value from map activity context and is set in constructor in this way:

public MiItemizedOverlay(Context context, Drawable defaultMarker) {
    super(boundCenterBottom(defaultMarker));
    this.context = context;

    populate();
}

To do this I've tried to use 'sartActivityForResult' instead 'this.content.startActivity(intent) in this way:

@Override
public boolean onTap(GeoPoint point, MapView mapView) { 

    boolean tapped = super.onTap(point, mapView);

    if (!tapped){           
        Intent intent = new Intent();
        intent.setClass(this.context, EditarLugarActivity.class);
        this.context.startActivityForResult (intent,1);
    return true;
}

but is not recognized by the compiler. 'this.context' is not working as it work for a simple 'startActivity'

Someone can help me with this? Thanks!

EDIT- Adding my MiItemizedOverlay class first line with 'extends':

public class MiItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context context; [....]
2

There are 2 answers

1
Kumaravel Selvaraj On

you can try

    Intent intent = new Intent();
    intent.setClass(getApplicationContext, EditarLugarActivity.class);
    this.context.startActivityForResult (intent);

or

Intent i = new Intent(this, EditarLugarActivity.class);
startActivityForResult(i, 1);
2
Rajeev On

There is no no method called startActivityForResult which takes only one argument.

Use, context.startActivityForResult(intent, 1); Here the second argument is the result code which would be returned back to you from EditarLugarActivity when finish() is called on that activity. You can define your own result code. And then you need to implement onActivityResult(int requestCode, int resultCode, Intent data) in your activity to catch this result code.

EDIT: StartActivityForResult method is from Activity class. So you need to call it as below

((Activity) this.context).startActivityForResult(intent, 1);

Make sure that your context is indeed an Activity context, and implement the onActivtyResult in the mapActivity.