Impact of Android Boot mode on experience

Source: Internet
Author: User

When it comes to Android's startup mode, people who know Android must understand it. By setting the startup mode we can not only save memory usage, but also achieve a better experience, such as we open an application, click the Home button back to the main interface when the program is not killed, when the click on the application and then come back if the settings have problems, Then it's possible to get back and load the boot page we wrote. This time we can set up our interface to use Sigletop, when we click the Home button, our current activity will be on the top of the stack, when the next time we come back to the top of the stack to load the interface will not appear this problem.

There is one I just met today: look at the picture.

When I click on QQ to jump to QQ after, do not log in, I press the back key will return to my application, but if you log in and then click the Back button to exit directly to the main interface.

Tune for half a day always feel that there is a problem, the various modes of activity in the XML file also modified for half a day, always dissatisfied. Finally, the flag attribute of the next intent is seen.


1. FLAG_ Activity_new_task :

When The intent object contains this tag, the system looks for or creates a new task to place the target activity, which is matched according to the Taskaffinity property of the target activity. If the taskaffinity of a task is found to be the same, the target activity is pressed into this task, and if the lookup is fruitless, a new task is created, The taskaffinity of the task is set to the taskactivity of the target activity, and the target activity is placed on this task. Note that if the taskaffinity of the activity in the same app uses the default or both sets the same value, it doesn't make sense to jump between activity in the app using this tag because the current application task is the best host for the target activity

2.flag_activity_clear_top:

When the intent object contains this tag, if an activity instance is found on the stack, the activity on top of the instance is emptied and placed on the stack. For example: Our firstactivity jumps to secondactivity,secondactivity jump to thirdactivity, and thirdactivity jumps to secondactivity, Then the thirdactivity instance will be ejected from the stack, so that the secondactivity is at the top of the stack and displayed before the screen, leaving only firstactivity and secondactivity in the stack. This secondactivity can either receive the intent in onnewintent (), or it can be destroyed and restarted to accept the intent. In the default "standard" startup mode, if the flag_activity_single_top tag is not used in intent, then it will be rebuilt after closing, if this flag_activity_single_top tag is used, Will use an existing instance, and for other startup modes, no longer use flag_activity_single_top, it will use an existing instance, and intent will be passed to the onnewintent () of the instance.

3.flag_activity_single_top:

when a target activity instance exists in the task and is at the top of the stack, no new one is created and the instance is directly exploited. We have also mentioned in the above example. the singletop effect is the same as in the activity startup mode.

4.flag_activity_clear_when_task_reset:

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(assuming: flag_activity_reset_task_ if_needed). 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. After testing, 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 flag, so the former will be cleared and the latter will not

5.flag_activity_reset_task_if_needed:

This tag will take effect in the following cases: 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 according to affinity, and the task presses into some activity instance or removes some activity instance

This is a few more common flag, by looking at the introduction of this may be able to find, in fact, I have to solve the problem is very simple, it is necessary to put our application and QQ this application into a different task, We then click the Back button to fetch the activity at the top of the stack in our app and then go back to our app, which is as simple as that.

Intent.setflags (Intent.flag_activity_new_task);

Intent's flag attribute is more, and may sometimes solve a lot of problems that are difficult to solve.

Impact of Android startup mode on experience

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.