Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Application lifecycle and activities

Tags:

android

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...

like image 700
Jim Avatar asked Oct 27 '25 03:10

Jim


2 Answers

There is a Life-cycle for the android application BUT the applications have limited control over their own life-cycle, instead the components must listen for changes in the application state and react accordingly, the changes are as the following

  1. onCreate
  2. onLowMemory
  3. onTrimMemory
  4. onConfigurationChanged

and these method are accessed by extending the application class and override them to react accordingly.

regards,

like image 173
Ali Saleh Avatar answered Oct 30 '25 10:10

Ali Saleh


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.

like image 22
stefan Avatar answered Oct 30 '25 11:10

stefan