Question

There are 4 main activities:

    ProfileMenu.class

    CreateNewProfileStepOne.class

    CreateNewProfileStepTwo.class

    MainMenu.class

Suppose from ProfileMenu.class, the user chooses "Create new profile" as an action. This launches CreateNewProfileStepOne.class, where the user enters data such as name, address, etc. The same goes on in CreateNewProfileStepTwo.class. At this point, the user may freely go back and forth between CreateNewProfileStepOne and CreateNewProfileStepTwo with all data being saved and passed via intents. If the user backs up from CreateNewProfileStepOne.class, all entered data is lost, and the user will have to enter from scratch again.

After hitting "Confirm Profile" button in the CreateNewProfileStepTwo.class activity, however, I want to send the user to MainMenu.class, as well as kill the previous activities ProfileMenu,CreateNewProfileStepOne and CreateNewProfileStepTwo.

How would I kill those 3 activities right as I enter MainMenu.class? From what I know, finish() only acts upon one and only one activity--the current one it is called from. I don't want to kill A,B,or C until I'm ready to enter D. And when I enter D, I want to kill A,B,and C simultaneously.

Was it helpful?

Solution

When you are creating an Intent to launch MainMenu add this flag to the Intent : Intent.FLAG_ACTIVITY_CLEAR_TOP

Intent i = new Intent(MyCurrentActivity.this, MainMenu.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

No history will be retained and the user won't be able to go back to the previous activities

OTHER TIPS

Activities are killed when you left them to go to another activity. Switching back and forth between these activities is done by recreating those activities.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top