Try to understand "Call startActivity from outside the activity context"

Need help understanding this exception:

   system_log_all 11-14 11:52:28.540 E/AndroidRuntime(31615): FATAL EXCEPTION: main
system_log_all 11-14 11:52:28.540 E/AndroidRuntime(31615): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
system_log_all 11-14 11:52:28.540 E/AndroidRuntime(31615):  at android.app.ContextImpl.startActivity(ContextImpl.java:689)
system_log_all 11-14 11:52:28.540 E/AndroidRuntime(31615):  at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
system_log_all 11-14 11:52:28.540 E/AndroidRuntime(31615):  at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)

What is the meaning of "outside the context of activity"? I don’t think I call "startActivity" from the "Application" Context, so what does that mean outside the context of activity?

Thank.

+5
source share
3 answers

To clear the previous answer, before you begin, you need to add the following:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Then Android will let you get started where you like it.

+8
source

As @thinksteep commented, you are trying to call startActivity()from something else, and then Activity.

Maybe you are trying to start activity with Service?

, , FLAG_ACTIVITY_NEW_TASK .

, , , , . .

..

+5

I know this a bit later, but I just got out of the same problem. so I would like to publish this in public, it may be useful for others who are in the same situation. I used Myclassname.thisinstead getApplicationContext();.

+2
source

All Articles