When two Activity Jump, when App switching front and back, when life cycle Activity Activity had to switch screens

When a, A, B two jump Activity

A start:

        A: onCreate -> A is created the first time
        A: onStart -> A visible
        A: onResume -> A ready to start interacting with the user

A start B:

        A: onPause -> A is about to start B
        B: the onCreate -> B is created the first time
        B: onStart -> B visible
        B: onResume -> B began to prepare interact with the user
        A: onStop -> A is not visible

B returns A:

        B: onPause -> B will return A
        A: onRestart -> A start again
        A: onStart -> A visible
        A: onResume -> A start preparing interact with the user
        B: onStop -> B is not visible
        B: onDestroy -> B is destroy

A Exit:

        A: onPause -> A defunct
        A: onStop -> A invisible
        A: onDestroy -> A be destroyed

PS: 1, onPause methods do not do time-consuming operation, otherwise it will affect the efficiency of the jump between the Activity, the user experience is very bad. For example the listener back to the background action should be placed in onStop, can not be placed in onPause. 2, if A jump B, onCreate B's, onStart, onResume life-cycle approach onStop A after the execution, due onStop method Activity is not already visible, will not create a cause A B is not visible has led to a black screen occurs .

Two, App before and after the switching station

A start after switching to the background:

        A: onCreate -> A is created the first time
        A: onStart -> A visible
        A: onResume -> A ready to start interacting with the user -> set background

        A: onPause -> A defunct
        A: onSaveInstanceState -> A state of preservation
        A: onStop -> A is not visible

A switching from the background to the foreground:

        A: onRestart -> A, was renewed
        A: onStart -> A visible
        A: onResume -> A ready to start interacting with the user

Three, Activity had to switch screens

1, is not configured android: configChanges when:  

       Horizontal \ vertical screen start: onCreate -> onStart -> onResume

       Horizontal \ vertical screen switching:

       onPause-->onSaveInstanceState-->onStop-->onDestroy-->onCreate-->onStart-->onRestoreInstanceState-->onResume

       退出:onPause -->onStop-->onDestroy

2, configure the android: configChanges = "orientation | keyboardHidden | screenSize" configure three different combinations, different systems, different mobile phone brands will perform lifecycle different situations.

                                                                                                     

Guess you like

Origin blog.csdn.net/cunjicsdn/article/details/88669145