I want to go back to MainActivity from any activities. For ex, my stack of activities: A - B - C - D. A (MainActivity) is in the bottom and D is in the top of stack .
When I use android:launchMode="singleTask"
. I can go back to A at any actvities as I expected.
But when I use flag FLAG_ACTIVITY_NEW_TASK
(without launchMode="singleTask"), it does not work as expected, it open a new Activity.
And stacks are:
A - B - C - D - A
not as document wrote:
FLAG_ACTIVITY_NEW_TASK
Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent().This produces the same behavior as the "singleTask" launchMode value, discussed in the previous section.
Anyone knows the reason? Thanks.
I hope this solution solve your problem::- Only set this to Intent
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);