Android: taskaffinity and Android: finishontasklaunch

Source: Internet
Author: User
Tags home screen

Recently, I made a call-related small app and used two properties that I usually know little about. I also saw the same foreign project. I started to copy it directly, I did not go into details. During the middle stage of the project, I deleted the properties of the Two-line configuration at will. I thought it was of little use because it was basically useless at ordinary times, and there was a small write problem. Let's record it here. Don't talk nonsense. paste the code and explain it directly. The following is my personal understanding after the test.

 

<Activity Android: Name = ". callscreen. callscreenactivity" Android: taskaffinity = "com. mythlink. callapp. callscreen"/> <! -- Android: taskaffinity: reassign a [task] Task Name (other activities can also use this name) [PS: because some projects require you to click the application icon, the main project interface must be displayed, with this attribute, it is easy to do. Assign another activity to taskaffinity, so that these interfaces will not be displayed, because the default taskaffinity stack is not the activity]. If you do not need to execute the onnewintent method in the activity, it is better to use Android: finishontasklaunch = "true. --> <Activity Android: Name = ". settings. contactsettingactivity" Android: finishontasklaunch = "true"/> <! -- Android: finishontasklaunch = "true" when the activity with this property set to true is returned to the [home screen] by pressing the Home key, and then clicking the app icon to start the program, the system will call [ondestroy] of the activity to destroy it. Because the task is restarted when you click the application icon to start the program. [PS: for some projects, clicking the application icon must display the main interface of the project and destroy some previously opened interfaces]. Currently, the [taskaffinity] task is not restarted. Therefore, you can only use the default system's taskaffinity and click the application icon to start the program. -->

 

Note:

The preceding two activities are not in the same task. If you enable callscreenactivity first and then contactsettingactivity, after contactsettingactivity executes ondestroy, it returns the activity with the same taskaffinity as it, instead of returning to the callscreenactivity interface, it will return to the corresponding activity interface in the previous taskaffinity only when there is no activity in the taskaffinity stack.

If both the two activities are configured as Android: launchmode = "singleinstance" mode, they are not managed by tasks. That is to say, the configuration of Android: finishontasklaunch is invalid. The Android: taskaffinity configuration also fails some of the functions here. Currently, it is known that it still has some features: After Android: excludefromrecents = "true" is configured, it will not be affected in different tasks, the same task system returns the top activity of the stack by default.

If the start mode is singleinstance, onactivityresult will be ineffective, and its resultcode will directly return activity. result_canceled.

 

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.