Reputation: 5717
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?
finish()
?onDestroy
is called)?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.
Upvotes: 11
Views: 10785
Reputation: 1
Definitly onDestroy()
is called .....There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish()
.
Upvotes: 0
Reputation: 14455
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.
Upvotes: 6
Reputation: 11514
When you press back, (if not intercepted by anything like the keyboard, fragment, activity, etc) the OS (via ActivityManager probably) will try to show the user the previous activity in your current task (again, ignoring fragments' back stack).
If there is no such activity, the task will be terminated and you'll go to the previous task - the home screen most of the times or some other application that might have launched your app.
You'll get onDestroy
called soon (it depends on how long it takes to start the next activity but on a good phone it should be under 100-200ms).
Your activity instance won't be reused after onFinish
. This happens before the activity is destroyed so if you need another activity of the same type, the OS will create another instance.
Upvotes: 2
Reputation: 24012
When the user presses the BACK key, the current activity is popped from the top of the stack (the activity is guaranteed to be destroyed, but not immediately, may be when the system resources are low) and the previous activity resumes (the previous state of its UI is restored).
Which actions does the back button/back key on Android trigger?
Upvotes: 1
Reputation: 1451
you use should look into this try this
and please tell specific what you wish to do with back button for your default activities ......
Upvotes: 2