Search code examples
androidandroid-activityback-stack

Handling (many) Back stacks


I have an App that has an specific task process of 3 steps, which are 3 different activities, when the process is done, there's an activity that shows you a message of the success and let you share it on social networks, copy it, save it, etc. After the success Activity, the App should return to the Main Activity.

First, I tried finishing each step activity when starting the next one, but the user should return to previous steps if wanted, so I discard it.

Now, I am calling the success activity as NEW_TASK and CLEAR_TOP, and when the Activity is calling the OnBackPressed() starting the MainActivity, of course it is not the right way and the Activity closes before the other starts, which make it feels buggy.

How can I handle the BackStack to make the steps activities can go back and forward, but when the success Activity is shown, go all the way back to the Main Activity.

This should be the Activity Flow:

Activity Flow Approach


Solution

  • After trying a lot of ways, the new start of the MainActivity was something that I didn't want, so I have to use Fragments, and Activities 1, 2, 3 and Success where replaced with just one Activity with 4 fragments and when the user finish the app finish the activity and return to the MainActivity.