Android task and back stack details 2: manage tasks

Source: Internet
Author: User
Save activity status

As described in the previous section, the system saves its status when the activity is stopped by default. as a result, when a user navigating to the previous activity, the user interface is displayed the same as when the user leaves. then, you can-and should-Use your activity callback method in advance to maintain its status, because the activity may be destroyed and re-created. when the system stops your activitie (for example, when a new activity is started or the task is moved to the background), the system may completely destroy the activity to release the memory. when this happens, the activity status is lost. if this happens, the system still knows that the activity occupies a position in the back stack, but when the activity is obtained to the foreground, the system must re-create it (rather than just restore it ). to avoid losing users' work, you should implementonSaveInstanceState()cTo save the status in advance.

For more information about saving activitystate, see http://blog.csdn.net/nkmnkm/article/details/7101178.


Manage tasks

Android manages tasks and backs up stacks, as described in the previous article-by placing all the activities that are successively started in the same task and in the same stack that is later-first-out-works well in most applications and you don't need to worry about your how the activity is related to the task or how it exists in the back stack. however, you may decide to break this normal behavior. you may want to start a new task (instead of placing it in the current stack) when the activity of your application is started; or, when you start an activity, you want to bring an instance that has been running to the foreground (instead of creating a new instance at the top of the back stack); or, when you want the user to leave the task, your rollback stack clears all the activities except the root activity.

You can do these things, or even more, by setting the <activity> attribute in manifest and passing it to the flag of the intent of startactivity.

At this point, the most important <activity> attributes you can set are:

Taskaffinity

Launchmode

Allowtaskreparenting

Cleartaskonlaunch

Alwaysretaintaskstate

Finishontasklaunch

The most important intent flag that can be used:

Flag_activity_new_task

Flag_activity_clear_top

Flag_activity_single_top

Note:Most applications should not changeActivityAnd default task behavior. If you are sure you must change the default behavior, you must be careful and ensure that the test is complete.ActivityThe availability of navigation at startup and backend ensures that navigation behaviors that conflict with user habits are tested.

Related Article

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.