Search code examples
androidandroid-activityonresumeonpauseondestroy

Android back button behaviour


Let's say we have a default, empty activity with default behaviour, launched with default intent flags. User presses back button on the device. The activity disappear... but how, actually?

  • Is pressing back button behaving the same way like finish()?
  • Is the activity immedietely destroyed (onDestroy is called)?
  • Is the activity guaranteed to be destroyed, but not immedietely?
  • Is there any chance the activity won't be destroyed and this instance will be reused when this activity is launched in the future? (so only onPause and onStop -> onStart and onResume are called?)

I'm looking for a reliable answer, so please do not answer if you are not absolutely sure what happens here.


Solution

  • http://developer.android.com/training/basics/activity-lifecycle/recreating.html

    This is a subchapter from the official Android documentation that addresses your question. It is a subchapter of the topic Managing the Activity Lifecycle, which can be read here: http://developer.android.com/training/basics/activity-lifecycle/index.html

    It is definitely worth reading the whole chapter to get to know the details about Androids Activity behaviour. But the subchapter ( first link ) is the relevant part to this question.