Search code examples
javaandroidandroid-activity

Android Activities Recreated


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 ?


Solution

  • 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()