Lifecycle Flashcards

1
Q

Explain the android activity lifecycle?

A

As a user navigates inside & outside of an app, the activities transition through different states.

A number of call-backs are provided to let the app know that there has been a state change.

We can use these call-back methods to manage how the app reacts to the changes in state.

For example, if we have a high data intensive app then we can unsubscribe from any data changes when the app is in the background and re-subscribe when the user resumes the app.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some examples of using life cycle callback methods?

A
  • A stock monitoring app can unsubscribe from price changes when the app triggers onPause() and re-subscribe on resume.
  • A video streaming app can pause the stream onPause(), resume at same point on resume.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the core six callback methods in the activity lifecycle?

A
  • onCreate()
  • onStart()
  • onResume()
  • onPause()
  • onStop()
  • onDestroy()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In what stage of the lifecycle can the app process be killed?

A

When the activity goes into the background or is no longer visible (onPause() / onStop()). The app process may then be killed because a higher priority app needs more memory. When the user navigates back to the app, the onCreate() method is executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In what situation is the onRestart() callback method called?

A

When the activity has entered the onStop() state and the user navigates back to the activity. The onStart() method is then called afterwards.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly