Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go back to a specific activity

Here's what I want to do:

enter image description here

If I use startActivity I start a new Activity and I can't use StartActivityForResult from Main Menu -> Total. I would like to go back on the Main Menu activity already present in my stack and remove Activities A, B ,C and Total.

like image 898
dierre Avatar asked Jan 02 '12 16:01

dierre


People also ask

How do I go back to previous activity?

In the second activity, the back button at the top left can be used to go back to the previous activity.

What code would you use to go back to a previous activity?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

How do I start the same activity again on Android?

If you just want to reload the activity, for whatever reason, you can use this. recreate(); where this is the Activity. This is never a good practice. Instead you should startActivity() for the same activity and call finish() in the current one.


1 Answers

Have you tried using FLAG_ACTIVITY_CLEAR_TOP flag in your intent (used to start "Main Menu" from "Total")?

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

like image 184
user1234567 Avatar answered Nov 15 '22 16:11

user1234567