I'm currently learning the Activity Lifecyle. I noticed the following:
Why gets A destroyed instead of restarted, when using the Up Botton in the ActionBar?
I hope my question is clear, if not please comment.
When you press the BACK button, this calls onBackPressed()
in the current Activity
. The default behaviour of that method (if not overridden in the Activity
) is to call finish()
on the Activity
. This finishes the Activity
and resumes the Activity
which is underneath it.
The UP button is calling startActivity()
with an Intent
that is built like this:
Intent intent = new Intent(this, TargetActivityForUpButton.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
This code will remove all activities in the stack back to, and including, TargetActivityForUpButton
. It then creates a new instance of TargetActivityForUpButton
and launches that Actvity
(you will see onCreate()
, onStart()
, onResume()
called on the Activity
.
See also the section "Navigate up to parent activity" in https://developer.android.com/training/implementing-navigation/ancestral