"Android API" Tasks and back Stack

Source: Internet
Author: User

Back Stack1. When the activity starts another new activity, the new activity enters the top of the stack, and the previous activity state changes to stopped, but its user interface is saved by the system. When the Back button is clicked, the current activity stack is destroyed and the previous activity is resume. 2. When all activity is out of stack, the back stack is empty and the task is destroyed.
3. When the home button is clicked, the current task is moved to the background save, and all activity in the task is in the stopped state. This task will continue when the app is started again from Applicaton launcher. 4. When there are too many tasks, they may be destroyed by the system. 5. Since the back stack stack will not be re-queued, when a particular activity is started from a different activity, it will be instantiated multiple times, then they will exist independently in the stack of the go stack and will not be replaced. 6. When an activity's task is moved to the background or a new activity is started, the activity may be destory by the system if there is not enough memory. At this point, when you switch to this task, or click the Back button to return to this activity, the system must recreate this activity, which will cause data loss in this activity. To avoid this behavior, you should inherit the Onsaveinstancestate () callback method in the activity to proactively save the activity. 7. The activity mode specified by the intent flag is higher than the mode priority specified in the manifest.
Defining launch Modesusing the manifest file1."Standard"The system creates a new instance of activity in the task that the activity initiates, which can be instantiated multiple times, each of which can be subordinate to different tasks. Each task can have more than one instance of the activity. 2."Singletop"If this activity is currently on the top of the back stack in the task, then when the activity is instantiated again, the system does not create a new instance, but instead points the intent to an existing instance. again, this activity can be instantiated multiple times,Each instance can belong to a different task, and each task can have more than one instance of that activity. A new instance of the activity is not created in this task only when it already exists at the top of the stack for a task. Once an activity instantiation is complete, you can return to the previous activity instance by clicking the Back button. However, when an existing instance processes intent, the onNewIntent()before the new intent arrives, you cannot click the Back button to return to the instance before this activity. 3."Singletask"A new task is created to store an instance of the activity as root activity. However, if an instance of the activity already exists in another task, the system will transfer intent to that instance in that task. Although this activity is in a new task, clicking the Back button in this activity will return to the Acitiviy before the activity. If an instance of this activity already exists in a task, the entire task is moved to the foreground and the instance of the activity is at the top of the stack. 4. "singleInstance"     与singleTask不同的是,保存此activity的task不会再保存其他activity实例。这种类型的activity的实例永远各自独占一个task。 Using Intent flags 1.FLAG_ACTIVITY_NEW_TASK     与singleTask作用一致 2.FLAG_ACTIVITY_SINGLE_TOP     与singleTop作用一致 3.FLAG_ACTIVITY_CLEAR_TOP      flag_activity_clear_top  and   flag_activity_new_task  often used together to locate an instance of the activity that already exists in another task, And put it in a position to accept intent.          中的需求需要 FLAG_ACTIVITY_CLEAR_TOP 与 FLAG_ACTIVITY_SINGLE_TOP 搭配使用,因为activity默认的mode是standard,那么只使用FLAG_ACTIVITY_CLEAR_TOP时,虽然将A 置于栈顶,但是是新建了一个A的实例替换掉了原来的A的实例。加上FLAG_ACTIVITY_SINGLE_TOP 则仍沿用原来的实例。
Handling affinities when no activity is setandroid:taskaffinity="string", this activity inherits application's affinity. Affinity works in the following two situations: 1.Flag_activity_new_task 2.android:allowtaskreparentingdetermines whether an activity can move from its start task to the task it has affinity. by definition, a root activity is always in the same affinity task. Since the activity of mode set to Singletask and singleinstance can only exist as root activity, re-parenting only for mode type The activity of standard and singletop is valid.
Starting a task Singletask and singleinstance can only be used for activity with Action_main and Category_launcher filter

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Android API" Tasks and back Stack

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.