I have gone through below documentation link :
https://android.jlelse.eu/android-activity-launch-mode-e0df1aa72242
Here, I understood the working of all the four Launch Modes namely :
Standard, SingleTop, SingleTask, SingleInstance.
Also got cleared about doing it practically by adding attribute 'android:launchMode'
in AndroidManifest.xml file.
Issue is with adding flags in Activity programmatically.
Now, From the Documentation it is said that :
FLAG_ACTIVITY_NEW_TASK
This flag works similar to “launchMode = singleTask”.
Now, To understood the behaviour of this, First I have checked it using AndroidManifest.xml. I have taken four Activities in my Project : A, B, C, D. Setted “launchMode = singleTask”
to my Activity C.
Navigation is like this From A -> B -> C -> D and from D -> C.
So, When I going from D to C its not creating new Activity C but letting me to Activity C. This is fine. Understood.
Now, I want to understood the same thing Programmatically.
So, For that I have removed static “launchMode = singleTask”
from the AndroidManifest.xml and doing it inside Activity C like below :
startActivity(Intent(ActivityC@this,ActivityD::class.java).setFlags(FLAG_ACTIVITY_NEW_TASK))
and In Activity DI have done as below :
startActivity(Intent(ActivityD@this,ActivityC::class.java))
But, this programmatic things not working like as I have done it with AndroidManifest.xml, It's opening New Activity C... instead of Going back towards Activity C.
What might be the issue ? or am I doing something wrong here ? Pls. guide. Thanks.
As per documentation,
FLAG_ACTIVITY_NEW_TASK produces the same behavior as the "singleTask" launchMode value.
So your going wrong in Activity D where you start Activity C. You should do,
startActivity(Intent(ActivityD@this,ActivityC::class.java)).setFlags(FLAG_ACTIVITY_NEW_TASK))
Setting FLAG_ACTIVITY_NEW_TASK when starting Activity D from C is not relevant.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.