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 D I 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,
So your going wrong in Activity D where you start Activity C. You should do,
Setting FLAG_ACTIVITY_NEW_TASK when starting Activity D from C is not relevant.