I am pretty new on Android Studio and I want to start an activity without closing the previous one. I have made some researches and the way to open activity is made by using Intent class and startActivity(intent), but in this way, the new page will be opened and if I want to go back to the previous one all the page will be fully recreated, and I want the previous page to remain at the same modifications. Can anybody help me with an advice ?
Asked
Active
Viewed 59 times
-2
-
Please check the life cycle of activity. – MehulGohil Jan 06 '20 at 12:29
-
this one help you most https://developer.android.com/guide/components/activities/tasks-and-back-stack – KuLdip PaTel Jan 06 '20 at 12:30
-
@MehulGohil Can you be more specific? – Adela Vîlcică Jan 06 '20 at 12:30
-
@AdelaVîlcică. Please check this link. https://developer.android.com/guide/components/activities/activity-lifecycle – MehulGohil Jan 06 '20 at 12:32
2 Answers
1
Say you are in activity A. You start activity B with:
Intent myIntent = new Intent(this, NextActivity.class);
startActivity(myIntent);
onPause() for current activity will be called before you go to myActivity, where onCreate() gets called. Now if you press back button, NextActivity's onPause() gets called, and you move back to activity A, where onResume() is called. Please read about activity life cycle in the docs here.
To save the state of an activity, onSaveInstanceState()

Ashish
- 6,791
- 3
- 26
- 48
0
Intent i = new Intent(this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
set Flag with intent

Ganesh Pokale
- 1,538
- 1
- 14
- 28