Skip to content Skip to sidebar Skip to footer

Resume Started Activity From Service

As I read in several stackoverflow answeres. To start activity from the service you have to use FLAG_ACTIVITY_NEW_TASK, but it will create new instance of activity in separate task

Solution 1:

In the manifest for the Activity, you could set android:launchMode="singleInstance".

Here's what the docs say about singleInstance:

Only allow one instance of this activity to ever be running. This activity gets a unique task with only itself running in it; if it is ever launched again with the same Intent, then that task will be brought forward and its Activity.onNewIntent() method called. If this activity tries to start a new activity, that new activity will be launched in a separate task. See the Tasks and Back Stack document for more details about tasks.

And here is where I got my info.

Solution 2:

You must use this flag with your Intent:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

IF you don't want a new instance of your Activity, set launchMode for your Activity in the AndroidManifest file:

android:launchMode="singleTask"

Post a Comment for "Resume Started Activity From Service"