Reputation: 21
Please, help me understand activity lyfecycle more deeply. http://developer.android.com/guide/components/activities.html#ImplementingLifecycleCallbacks They say:
The foreground lifetime of an activity happens between the call to onResume() and the call to onPause().
Does this mean, that activity becomes resumed in some moment after onResume() is called, or after onResume() completely finished it's work? Similar question about visible state and onStart. And if the second is right (method completely finished it's work), then super.method() or overriden by me in activity class?
@Override
protected void onResume() {
super.onResume();
// is it now "resumed" after super.onResume()?
}
Upvotes: 0
Views: 433
Reputation: 48871
The foreground lifetime of an activity happens between the call to onResume() and the call to onPause().
Does this mean, that activity becomes resumed in some moment after onResume() is called, or after onResume() completely finished it's work?
Technically speaking, the Activity
is in a state of being resumed before onResume()
is called but the option for you to override the onResume()
method allows you to fine-tune what needs to be done before the Activity
enters the 'running' state. In other words, from the point of view of the OS, the Activity
is resumed, then onResume()
is called and, finally, from the point of view of your own individual app, resuming the Activity
is complete when onResume()
is complete and the Activity
is running.
Similar question about visible state and onStart. And if the second is right (method completely finished it's work), then super.method() or overriden by me in activity class?
Again, the same logic applies - the OS goes through what it needs to do to start the Activity
then calls onStart()
for you to customise the starting stage of your Activity
. The OS considers the Activity
to have started before it calls onStart()
but from your app's perspective, it hasn't completely become started until any code you have in your overridden onStart()
method.
Upvotes: 0
Reputation: 412
"The foreground lifetime of an activity" referes to the time it is directly being shown to the user. It also implies at the moment its process has maximun priority on the Android process priority ladder. You should read this http://developer.android.com/guide/components/processes-and-threads.html
Furthermore, onResume()
, onPause()
... are just hooks where you should insert code that needs to be executed on that specific moment of the activity lifcycle.
Upvotes: 1