I want to set the onBackPress button to start activities that started before orderly. If I don't finish activities that started before when I start another activity, I can show the activity that started before with finish() current activity. This is possible. Because I don't finish any activity. So finish() current activity will cause show activity that started before. But, RAM will be overload when I open 50 activities may be. So because of this problem I need to finish() activity that started before. On the other hand, I want to start the activity that started before orderly when clicking to the back button. For example
ActivityA --> ActivityB --> ActivityC --> ActivityD
In this scenario, I finish ActivityA, ActivityB, ActivityC orderly. But I want to start ActivityC back press of the ActivityD and I want to start ActivityB on the back press of ActivityC.
Lastly, I have a complex path in the application. And, I navigate to the ActivityD and I finished the ActivityF when my current activity is ActivityF
ActivityF --> ActivityD
ActivityF finished
Current activity:
ActivityD
In this scenario, I want to start the ActivityF not the ActivityC on back button of the ActivityD.
Normally:
ActivityA --> ActivityB --> ActivityC --> ActivityD /// click back button
ActivityA --> ActivityB --> ActivityC /// click back button
ActivityA --> ActivityB /// click back button
ActivityA
or
ActivityA --> ActivityF --> ActivityD /// click back button
ActivityA --> ActivityF /// click back button
ActivityA
But I want to generate this scenario:
ActivityA
--> ActivityB
--> ActivityC
--> ActivityD /// click back button
ActivityC <-- /// click back button
ActivityB <-- /// click back button
ActivityA
or
ActivityA
--> ActivityF
--> ActivityD /// click back button
ActivityF <-- /// click back button
ActivityA <--
Update:
I found the solution here