Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.

FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_NEW_TASK
HA HA HA !!, You got this error, right ? if yes then you most probably called startActivity() from a ListView item click, If not then you may be called from somewhere else. As you can see that error clearly says that startActivity() from outside of an activity, mostly this case is generated in notification click because that time there is no activity and we are trying to open another activity.

Error :

 
Stack trace:  
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:672)
at android.app.ContextImpl.startActivity(ContextImpl.java:659)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
at com.t2tor.main.notification.NotificationAdapter.gotoStripeAccount(NotificationAdapter.java:212)
at com.t2tor.main.notification.NotificationAdapter.access$400(NotificationAdapter.java:34)
at com.t2tor.main.notification.NotificationAdapter$1.onClick(NotificationAdapter.java:146)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Solution :

There are two solutions you can implement one of them.
1. Use getActivity() instead of getApplicationContext() in ListAdapter constructor.
for example :
ListAdaper adapter=new ListAdapter(getActivity(),[YOUR LIST]);

2. Add flag to your intent, if you have notification case.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Comments

Post a Comment