Again on the life cycle of an activity: onStart is called when it should not be

First of all, I read a great explanation of how actions begin, pause, resume, and stop . This is normal, but I have a different problem.

The activity lifecycle diagram in the Android link says that if I call another action, onPause () is called for the calling activity, and later, when the other action is completed, the caller will be resumed via onResume ().

So, if the first activity is Main, and the other is Other, the loop will look like this (pseudocode):

Main.onCreate() Main.onStart() Main.onResume() // Main is running... Then, the user clicks a button and Other comes in front. Main.onPause() Other.onCreate() // Other lifecycle goes here... Finally, the user returns back. Main.onResume() // Main is running again. 

This is what the chart reports. But my Main gets onStart () first, then onResume ().

Why? Do I not understand something?

+4
source share
2 answers

This is because the main activity completely disappears from the view, which causes onStop, which causes OnStart to resume. If you only partially hid the view from your Main, you would only get onResume.

If you look at the diagram between onPause and onStop, this β€œaction is no longer visible” ... this is what you are facing.

For quick reference, the activity lifecycle chart:

enter image description here

+5
source

One of the reasons your onStart() is calling is for the main application, so the main action stops. This is called its onStop() . In this scenario, first will be onStart() , and then onResume() .

+1
source

Source: https://habr.com/ru/post/1411145/


All Articles