Android startup mode

First, analyze the life cycle of Activity

A jump B (A finish) sequence lifecycle

onPause(A)— onCreate(B)— onStart(B)— onResume(B)— onStop(A)— onDestroy(A)

A jump back B A (B Finish) sequence lifecycle

onPause(A)— onCreate(B)— onStart(B)— onResume(B)— onStop(A)— onPause(B)— onRestart (A)— onStart(A)— onResume(A)— onStop(B)— onDestroy(B)

Note:
onPause can do some stored data, stop animation, but be careful not to be too time-consuming. As can be seen from a life cycle, it must onPause A method of executing the new activity can perform.

onStop can do a little heavyweight recycling efforts, but the same can not be too time-consuming.

onDestroy can do some recycling and final release of resources. (For example a single database applications are not suitable for this destruction).

Activity startup mode

standard standard mode (default mode of the system)

Features: Each time you start an activity, will create a new instance, regardless of the instance exists in the current stack.
Scenario: General Interface is this model

Non-activity type Context (such as ApplicationContext) can not go directly to a start activity, because it is not the task of the so-called stack. However, if the use of non-activity type of Context to start an activity, and the activity to be started is specified FLAG_ACTIVITY_NEW_TASK flag, then there is no problem (the equivalent of the way to be initiated activity singleTask mode is activated).

multiplexing mode stack singleTop

Characteristics: equivalent to intent.addFlags (Intent.FLAG_ ACTIVIT_ SINGLE_TOP).
Scenario: After notification bar click on the need to start an active page (the page may already exist in the stack)

If A is already in the top of the stack, then start again A, A will not rebuild again, will reuse existing A stack, and call the onNewIntent Method A.
If A is not on top of the stack, start again A, A will be rebuilt.

The multiplexing mode stack singleTask

Features: equivalent to intent.addFlags (Intent.FLAG_ ACTIVIT_ NEW_TASK)
application scenarios: APP Home

Single instance mode, within a stack, no matter how many times to start, there is only one instance.
Each time you restart onNewIntent method activity, will call activity already exist. The activity of the task stack and emptied all the activity above.

Examples of single-mode singleInstance

Features: has all the features singleTask mode.
Scenario: call incoming call interface

Activity in this mode, the system will create a new task stack. Stack and only one instance of the activity. Rather: that it will take up a task alone, any activity would be his turn to run in other tasks.
The active mode is activated globally unique, i.e. only one such example exists throughout the system.

With two very start mode

A demand: ABCD turn on, and then jump B D CD will finish out hope.

Scenario 1: Start mode B is set singleTask.

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Scheme 2: D B jump time, add the following tag

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

(Note: Role 2: If the startup mode B is the default, then the BCD will finish, B will rebuild, reconstruction in order to prevent B)

Demand II: ABCD turn on, start C from D, but not into ABCDC but ABDC.

Operation: D B jump time, add the following tag

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)

Guess you like

Origin www.cnblogs.com/io1024/p/11532764.html