Android back button behaviour

Sebastian Nowak picture Sebastian Nowak · Jul 23, 2012 · Viewed 10.2k times · Source

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.

Answer

Dennis picture Dennis · Jul 23, 2012

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.