I have an Activity A
. Activity A
has a button called Add to Favorites
.
If the user is not logged in then it will take him to Activity B
(the login page). The login page has a button If New User please Register
If user is not registered then onclicking If New User please Register
it will take him to Activity C
(Sign Up form).
After successfully filling the form it will go to Activity D
for entering OTP.
Now if the OTP is correct I want to go back to Activity A
from Activity D
So how to do this with startAcitivity.
Start activity A with ClearTop.
Intent activityA = new Intent(this, ActivityA.class);
activityA.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(a);
This flag starts the activity in question and clears all other activities that are on top of it in the stack. It will launch activity A from its previous state. So if there was an activity beneath it in the stack then the back button will still work correctly.
Here is some useful information on the backstack and how to manage it. https://developer.android.com/guide/components/activities/tasks-and-back-stack
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.