Two startup modes for ACTIVITY: Flag_activity_clear_top and Flag_activity_reorder_to_front
1. If four activity:a,b,c and d have been started. In the D activity, we want to jump to B activity and hope c,d finish off, you can add the flags tag in the intent of startactivity (intent), as follows:
Java code
- Intent Intent = new Intent (this, b.class);
- Intent.setflags (Intent.flag_activity_clear_top);
- StartActivity (Intent);
This starts B activity, you will finished d,c, if your activity's startup mode is the default (multiple), then B activity will finished off, and then start a new Activity B.
If you do not want to re-create a new B Activity, add it in the code above:
Java code
- Intent.addflags (Intent.flag_activity_single_top);
b activity will then create a new one, but will reuse the previous B activity, while invoking the B activity's Onnewintent () method.
2. If you have started four activity:a,b,c and D, in D activity, want to start a actvity B, but not become a,b,c,d,b, but want to be a,c,d,b, you can write code like the following:
Java code
- Intent Intent = new Intent (this, mainactivity.class);
- Intent.addflags (Intent.flag_activity_reorder_to_front);
- StartActivity (Intent);
In addition, intent contains several other flag flags.
Intent.flag_activity_new_task
The default jump type will recreate a new activity, but in this case, for example, there are a,b,c three activity in the stack, when D is started in C, If the value added to D in the Manifest.xml file is different from the affinity in the task, the activity is pressed into the task that exists in the newly tagged affinity. If the default or specified affinity and task are the same, start a new activity just like the standard mode.
Flag_activity_no_history
This means that with this flag activated activity, once launched, he will not exist in the stack, the original is a,b,c this time again C with this flag to start D, D and then start E, this time the situation in the stack is a,b,c,e.
Flag_activity_brought_to_front
This means recreating a new activity (even if the activity already exists on the stack) and mentioning the top of the stack.
For example, a,b,c,d are standard loading, and then I start a in D, this intent plus flag_activity_brought_to_front, do not mistakenly think to become b,c,d,a!! Actually not, this time should be a,b,c,d,a. People who don't believe, try it. But the following mark and this mark will make everyone understand!
Flag_activity_reorder_to_front differences
This means that if the stack already exists, it will be taken to the top of the stack and no new activity will be initiated. For example, there are a,b,c three activity in the stack. When you start a in C, the order of the stacks is b,c,a.
Reference:
The intent object plays an important role in Android development, its built-in rich constants for passing data, the following describes some of the flag parameters related to the task, the understanding of each parameter from the Android API and I experience in the actual project, If there is any improper description, please do not hesitate to enlighten you.
Flag_activity_brought_to_front: This flag is generally not set by the program code, such as setting the Singletask mode in the Launchmode system to help you set.
Flag_activity_clear_top: If the target activity is already running in the current task, close all activity in the activity stack above this activity, This intent is then passed to the activity instance. For example, suppose a task's activity stack contains these activity:a,b,c,d. If D calls StartActivity () and intent points to B, then both C and D end, and B receives the intent, so the current state of the stack is: A, B.
Flag_activity_clear_when_task_reset: If set, this sets a restore point in the activity stack of the task, and when the task resumes, it needs to clean up the activity. For example, when the next TASK enters the foreground with the flag_activity_reset_task_if_needed tag, the activity and the above will be closed so that the user can no longer return to them, but may return to the previous activity.
Flag_activity_exclude_from_recents: If set, the new activity will not be saved in the list of recently launched activity.
Flag_activity_forward_result: If set, and this intent is used to initiate a new activity from an existing activity, then, This activity, which is the target of the response, will be passed on to the new activity. In this way, the new activity can call Setresult (int), and the resulting value will be sent to the activity that is the target of the reply.
Flag_activity_launched_from_history: This flag is generally not set by the application code, if the ACTIVITY is started from the history (often press the home button), then the system will help you set.
Flag_activity_multiple_task: It is not recommended to use this flag unless you implement the Application Launcher yourself.
Flag_activity_new_task: The ACTIVITY will be the beginning of a new TASK.
Flag_activity_no_animation: This flag will prevent the system from entering the next ACTIVITY when applying acitivity migration animations.
Flag_activity_no_history: The new ACTIVITY will no longer be preserved in the history stack. Once left, the activity is closed.
Flag_activity_no_user_action: This flag blocks the Onuserleavehint () from the front-most activity callback before the activity pauses.
Flag_activity_previous_is_top:if set and this intent was being used to launch a new ACTIVITY from an existing one, the cur Rent activity is not being counted as the top activity for deciding whether the new intent should is delivered to the top I Nstead of starting a new one. The previous activity is used as the top, with the assumption being that the current activity would finish itself imme Diately.
Flag_activity_reorder_to_front: This flag will cause the ACTIVITY that is already running to move to the top of the history stack.
Flag_activity_reset_task_if_needed:if set, and this ACTIVITY are either being started in a new TASK or bringing to the top An existing task and then it'll be launched as the front door of the task. This would result in the application of any affinities needed to having that task in the proper state (either moving Activiti Es to or from it), or simply resetting this task to its initial state if needed.
Flag_activity_single_top: If the activity is at the top of the activity stack, a new instance is no longer created.
The intent built-in parameters can be used for simple Android applications, but once the Android app is too complex, customizing an activity list to manage activity is a better and more efficient way to manage it.
Flag_activity_clear_top and Flag_activity_reorder_to_front usage