'single instance of an activity in android
I know single instance can be achived by setting android:launchMode="singleInstance" in menifest file. but i want to do it on run time . I think it can be achived by setting FLAG but not sure witch one.. plzz help me.. thanks in advance.
Solution 1:[1]
This is what u 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 Manifest
Solution 2:[2]
singleInstance specifies that the launched or recycled activity will be created on a new or existing task, and no other activities can be stacked on top of it. The system will ensure any activities started from it are put on other tasks.
1 task and 1 activity.
There is no intent flag that I know of that will prevent further activities launched by your activity without having to specify flags in all of your new activity's created intents.
So the answer is this is not possible.
Previous posted answers imitate how this will look, but the behavior goes against the specification.
Solution 3:[3]
you can achieve singleInstance behaviour with this flags Intent.FLAG_ACTIVITY_MULTIPLE_TASK, Intent.FLAG_ACTIVITY_NEW_TASK
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pixelscreen |
| Solution 2 | Steven Spungin |
| Solution 3 | Volodymyr Sheludchenko |
