Jim Jim - 5 months ago 9
Android Question

Android: Application lifecycle and activities

Trying to found some information about Android app life cycle. So imagine the situation: I open app and than lock screen, and in a few hours phone kill my app process. What will happen when I will unlock screen ? What I will see at the screen ? Android home screen ? or App will restar automatically for me ? Will stack of activities will restore too ? I'll be glad for any help. Thanks...

Answer

Activity lifecycle is what your looking for.

There is no such thing as Application lifecycle or lifecircle. Every Activity has it's own lifecycle. If the system needs more ram it will be killed if in onPause() or onStop() state. If all your Activities are killed, the app is no longer visible. If you want data to persist you have to Override onPause() and onResume() and save/restore your data there.

Your Application will never restore on its own, if there is an activity killed. You have to keep track of your activities manually if you want to "resume" after kill of your activities.

To make it even more precise: One Activity can be killed and the others can remain paused. If you then return to your app you get the last activity in your activity stack which wasn't killed.

Comments