0

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; [....]
  • have you tried it as `intent.setClass(context, EditarLugarActivity.class);` or `intent.setClass(MiItemizedOverlay.this.context, EditarLugarActivity.class);` ? because in your case `this` refer to the method context instead of class and context is field of class instead of `onTap` method – ρяσѕρєя K Jul 12 '13 at 16:48
  • Thanks for helping. I've tried what you are proposing but it not resolve my problem. Still can't call startActivityForResult function. – user2548358 Jul 14 '13 at 19:26

2 Answers2

0

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);
  • Thanks for helping. I've tried that but 'MiItemizedOverlay' class extends ItemizedOverlay. I can't call 'getApplicationContext' as I can't call startActivityForResult – user2548358 Jul 14 '13 at 19:38
0

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.

Rajeev
  • 1,374
  • 1
  • 11
  • 18
  • Thanks for helping. That is a copy-paste mistake... my fault. I was trying to call startActivityForResult as you describe but is 'undefined' and no import suggested by my editor. Same problem when I try to override onActivityResult function. ¿Maybe I'm missing something on MiItemizedOverlay class? – user2548358 Jul 14 '13 at 19:33
  • Please check my edit in the original answer. And you should not face any issue in Overriding the `onActivityResult` method. Make sure to implement that method in mapActivity class. – Rajeev Jul 14 '13 at 20:13