Android Activity launch mode knowledge Point Summary

Source: Internet
Author: User
<span id="Label3"></p><p><p>Read</p></p><p><p>http://my.oschina.net/u/1244156/blog/228483</p></p><p><p></p></p><p><p><strong>Flag_activity_new_task</strong></p></p><p><p>The task stack that is determined by the callee taskaffinity (if You do not define the package name of the application that is the Default) (that is, if you have only a a, b application, open the application A with newtask or in the same task Stack)</p></p><p><p><strong>Flag_activity_clear_top</strong></p></p><p><p>Clears the activity of the callee above the task stack (including the caller, that is, the Ondestroy,oncreate method called B)</p></p><p><p><strong>Flag_activity_single_top</strong></p></p><p><p>Call the Onnewintent () method directly if the top of the stack is the callee</p></p><p><p><span style="background-color: #cc99ff;"><strong>note:</strong> <span style="font-size: 16px;">Flag_activity_clear_top and Flag_activity_single_top equivalent to singletask,singleinstance in Launchmode That is: clear the activity above and call the Onnewintent method</span></span></p></p><p><p><strong>Flag_activity_brought_to_front</strong></p></p><p><p>If the activity is present in the task and gets to the top, no new activity is started</p></p><p><p><strong>Flag_activity_clear_when_task_reset</strong></p></p><p><p>If a intent contains this attribute, then the activity it turns to and all activity on that activity will be purged from the task when the task is Reset. When we return a back-end task to the foreground, the system will have a flag_activity_reset_task_if_needed tag attached to the action in a particular case, which means that the task is reset if necessary, flag_activity_clear _when_task_reset will take Effect.</p></p><p><p>Note:</p></p><p><p>After testing, <span style="background-color: #cc99ff;">for a background application, if the main menu click on the application, this action contains flag_activity_reset_task_if_needed tag, Long press the home key, and then click the recent record, this action does not contain flag_ Activity_reset_task_if_needed tags, So the former will be cleared, the latter will Not. </span>for this mark, you can show:</p></p><p><p></p></p><p><p></p></p><p><p><strong>flag_activity_reset_task_if_needed</strong></p></p><p><p>1. Create a new task to place the activity instance when the activity is started; 2. The existing task is placed in the Foreground. The specified task is reset based on affinity, and the task presses into some activity instance or removes some activity instances.</p></p><p><p>Note: launch the app from launcher</p></p><p><p></p></p><p><p><strong>task-related Properties for <activity></strong></p></p><p><p><strong>1.android:allowtaskreparenting</strong></p></p><p><p>Flag an activity instance after the current application has retired, can it move from the task that started it to a task with common affinity, "true" means that it can be moved, "false" means it must be in the currently applied task, the default value is False.</p></p><p><p>Eg: for example, to view a Web page in an application, after launching the system browser activity, the activity instance is in the same task as the current application, and when our app is back in the background, the user launches the app from the main menu Again. At this point the activity instance will be re-hosted into the browser Application's task, and the activity instance will not be seen in our application, and if you start the browser application at this point, you will find that the first interface is the Web page we just opened, proves that the activity instance is actually hosted within the task of the browser Application.</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><strong>2.android:alwaysretaintaskstate</strong></p></p><p><p>This property is used to mark whether the applied task remains in its original state, "true" means that it is always persisted, "false" means that it is not guaranteed, and the default is "false". This property only works on the root activity of a task, and other activity is Ignored.</p></p><p><p>By default, If an app is in the background for too long, for example 30 minutes, when the user selects the app from the main menu again, the system cleans up the Application's task, except the root activity, the other activity will be cleared out of the STACK. however, If you set this property in root activity, you can still see the interface of the previous operation when the user launches the app Again.</p></p><p><p>This property is useful for some applications, such as browser applications, where there are many states, such as opening a lot of tabs, and users do not want to lose these states, and using this property is extremely appropriate.</p></p><p><p><strong>3.android:cleartaskonlaunch</strong></p></p><p><p>This property is used to mark whether all activity except the root activity is purged from the task, "true" means clear, "false" means no cleanup, and the default is "false". similarly, This property only works on root activity, and other activity is Ignored.</p></p><p><p>If this property is set to "true", each time the user restarts the app, it will only see that the other activity in the root activity,task is cleared out of the STACK. If the activity of other apps is referenced in our app, These activity sets the Allowtaskreparenting property to "true", then they are re-hosted into a task with common Affinity.</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><strong>4.android:finishontasklaunch</strong></p></p><p><p>This property is similar to the android:allowreparenting property, except that the Allowreparenting property is re-hosted into a task with a common affinity, and the Finishontasklaunch property is destroying the Instance. If this property and android:allowreparenting are set to "true", this property wins</p></p><p><p>Android Activity launch mode knowledge Point Summary</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.