Reputation: 11
here's my problem:
At the moment I have a broadcastReceiver which is able to start a new instance of activity A when the call takes place. If I start activity A from there with "FLAG_ACTIVITY_SINGLE_TOP", I get the error
Calling startActivity() from outside of an Activity
context requires the FLAG_ACTIVITY_NEW_TASK flag.
Is this really what you want?
But I don't want a new task, I want to RESUME activity A
Thanks a lot!
EDIT: Perhaps I could simply simulate a click on the BACK-button?
Upvotes: 0
Views: 988
Reputation: 2249
Considering your use case - BroadcastReceiver that doesn't have a tasks in which to start the activity - singleTask
in the manifest should do what you want.
"singleTask" The system creates a new task and instantiates the activity at the root of the new task. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance. Only one instance of the activity can exist at a time.
Note: Although the activity starts in a new task, the Back button still returns the user to the previous activity.
Taken from: http://developer.android.com/guide/components/tasks-and-back-stack.html
Upvotes: 1
Reputation: 2249
Have you tried using FLAG_ACTIVITY_REORDER_TO_FRONT
?
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT
It seems to do exactly what you need.
Upvotes: 0