One action instance in android

I know that one instance can be achieved by setting android:launchMode="singleInstance" in the manifest file. but I want to do this at runtime. I think this can be achieved by installing FLAG , but not sure if this is a witch .. plzz help me .. thanks in advance.

+4
source share
3 answers

In general, you can use a combination of Intent.FLAG_ACTIVITY_SINGLE_TOP , Intent.FLAG_ACTIVITY_CLEAR_TOP , Intent.FLAG_ACTIVITY_REORDER_TO_FRONT and Intent.FLAG_ACTIVITY_NEW_TASK to accomplish what you want. However, which one (or those) to use depends on the situation that you have.

+5
source

This is what you are looking for

 Intent intent= new Intent(context, YourActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

UPDATE: android:launchMode="singleInstance" may also be needed in the manifest

+3
source

singleInstance indicates that a launched or redesigned activity will be created on a new or existing task, and no other actions can be stacked on top of it . The system guarantees that any actions launched from it will be applied to other tasks.

1 task and 1 activity.

The flag of intent, of which I am aware, will impede further actions triggered by your activity, without the need to indicate flags in all your new actions.

So the answer is impossible .

The previous posted answers imitate how it will look, but the behavior is contrary to the specification.

0
source

All Articles