Search code examples
androidandroid-activityandroid-lifecyclerestart

Android Activity lifecycle, restarting app instead of restart activity


I developed an Android app recently. Everything goes well until I press home key on my devices. On one of my devices (which has more memory), activity resumes in right state and my app runs well. But on other device, activity kills after some seconds and when I resume app it restarts the activity that I left with default values (incorrect behavior). How can I force app to restart app from main activity instead of restarting this activity with default values?


Solution

  • Finally I got the answer:

    We have to set a global static variable in main activity in onCreate() and finish if that variable had been reset to null in activity that we left the app!