I have an app which is one activity.
Everything works as I would expect except when I put the phone (a Samsung Galaxy Ace running Gingerbread) to sleep with the button on the side. When I do this, the following are called (in this order):
onPause, onStop, onDestroy, onCreate, onStart, onResume, onPause.
This is without waking the phone up, it is still asleep - screen is off.
Why is the activity killed completely and re-recreated?
Even more bizarre, if the phone is then switched back on the following happens:
onResume, onPause, onStop, onDestroyed, onCreate, onStart, onResume
Even though it's 'ready to go' (sitting in onPause), it gets killed and re-created all over again.
If the app is running and I press Home then the activity is only stopped, not killed, once stopped, I can then put the phone to sleep and then wake it up again and the activity is never killed. It just goes to onRestart etc... which is what I would expect.
This behaviour only occurs when the phone is put to sleep while the activity is running (and in the foreground).
I've read the docs on the Activity Lifecycle but I can't figure out why this behaviour occurs.