A. Simple scenario (closed app)
Actions to reproduce behaviour:
- Turn off the screen
- Run application from Android Studio (at this point no lifecycle method has been called yet)
- Turn on the screen
Here's the launcher activity lifecycle:
// we turn on the screen
- onCreate()
- onStart()
- onResume()
// launcher activity here suddenly decides to stop and restart
- onPause() // Is this a BUG?
- onStop()
- onRestart()
- onStart()
- onResume()
B. Lock-screen scenario
Actions to reproduce behaviour:
- Turn off the screen (you should have a lock screen)
- Send push to your app
- Open the lock screen and click on push notification
C. Scenario when activity was already opened
Actions to reproduce behaviour:
- Open your app (in launcher activity)
- Turn off the screen
- Send push
- Open push from lock screen
Here's the launcher activity lifecycle:
// open activity like a normal person :)
- onCreate()
- onStart()
- onResume()
// turn off the screen causes onStop(), everythin OK
- onPause()
- onStop()
// send push and click it from lock screen
- onRestart() // FIRST RESTART because we stopped activity, it's OK
- onStart()
- onResume()
- onPause() // Is this a BUG?
- onStop()
- onRestart()
- onStart()
- onResume()
- onPause()
- onStop()
Finally
This lifecycle order and restarting does not seem very reasonable to me. Does anyone have any idea why this happens?