In Android activity lifecycle, do onStop() and onDestroy() always called? Why? Moreover, please named the state definitely called in activity lifecycle? Many thanks
Asked
Active
Viewed 3,995 times
-5
-
http://developer.android.com/intl/ru/training/basics/activity-lifecycle/starting.html – Vyacheslav Jan 26 '16 at 04:55
-
http://developer.android.com/intl/pt-br/guide/components/activities.html – Amit Vaghela Jan 26 '16 at 04:57
-
`onStop()` is called when the app goes in background and android is stopping the particular activity. Similarly `onDestroy()` is called when Android is destroying particular activity. Both are called on different ocassions – Murtaza Khursheed Hussain Jan 26 '16 at 04:58
1 Answers
1
I have attached an image of the Activity lifecycle. When an activity is first run, it will call onCreate(), and after it is created, it will call onStart() to get the activity started which proceed on to onResume(). When the application enter another activity, the previous activity will be onPause() and onStop if I'm not wrong.
If you exit the activity by pressing the back button (destroying), it will be onPause() -> onStop() -> onDestroy()
If you enter activity B from activity A, it will be onPause() -> onStop()
If you enter activity B, it will be depending on whether the activity is destroyed or it just stop. If it's stop, it will be onStart() -> onResume().
If it's destroyed, it will be onCreate() -> onStart() -> onResume()
(diagram source)

Jean-François Fabre
- 137,073
- 23
- 153
- 219

Ophitect
- 543
- 4
- 18