What methods are invoked in the Activity Lifecycle in the following cases:

user432209 picture user432209 · Feb 16, 2011 · Viewed 22.1k times · Source

Let's say I have a Hello World single Activity application. I start this application.

What methods are invoked in each case:

  • Home button is pressed: ?
    Back button is pressed: ?
    Phone call is received: ?

What methods are invoked once the user starts the application again via the app icon (assuming the OS hasn't had a "other apps need memory condition"):

  • Home button was pressed: ?
    Back button was pressed: ?
    Phone call was received: ?

Thanks all.

Edit: Extra Credit: How can the user invoke onPause without invoking onStop?

Answer

bigstones picture bigstones · Feb 16, 2011

both pressing home button and receiving a call don't remove the activity from the task's stack, and will be available when you re-enter the app => onPause() => onStop().

as the activity lifecycle diagram shows, re-entering the app calls => onRestart() => onStart() => onResume()

pressing the back button instead kills the activity => onPause() => onStop() => onDestroy()

re-entering the app in this case calls the classics => onCreate() => onStart() => onResume()

EDIT

from http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.