1

In my MainActivity I have buttons which allow me to open other activities, and, inside of these, I have more buttons that open more activities…

The question is this:

When I am, let's say, in the third sub-level of activities, I have added a menu_button that allows me to go back to the MainActivity. But, when I click it, the MainActivity opens, but it obviously does not close the others. How can I do that?

This is the current block of code that makes the jump:

case Resource.Id.home:

Intent intent = new Intent (this, typeof(MainActivity));
this.StartActivity(intent);

return true;

2 Answers 2

3

This is how you should do it

Intent intent = new Intent (this, typeof(MainActivity));
intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask);
this.StartActivity(intent);
0
1

Do you want to keep any of the activities besides the Main one in backstack at all?

If not, you can open each one without adding them to backstack. See example here Android: open activity without save into the stack

2

Not the answer you're looking for? Browse other questions tagged or ask your own question.