Issue Starting Activity From Non-activity Class
I am a noob to android and I have a Map Activity that also uses OverlayItems. Within the onButtonTap method of my overlay class, I want to execute startActivity so i can then use i
Solution 1:
you can create method in your MapActivity class like this to get context...
Edit : Take some static variable like this...
publicstatic Context mContext;
In Activity's onCreate() method assign base context to it...
mContext = getBaseContext();
& return mContext...
publicstatic Context getContext() {
return mContext;
}
& call it in to your non activity class to start activity...
IntentcallIntent=newIntent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setData(Uri.parse("tel:"+MapActivity.phonenumber0));
MapActivity.getContext().startActivity(callIntent);
Solution 2:
Try this before start the activity set this flag :
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Hope it will work.
Solution 3:
You can pass the context of the activity (Map Activity) to your class and then use it..
Post a Comment for "Issue Starting Activity From Non-activity Class"