Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use flag_activity_new_task

Shulou Source: shulou.com Published: 2022-06-03 11:01:50 10月26日 Update

This article mainly introduces how to use flag_activity_new_task, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The FLAG_ACTIVITY_NEW_TASK comparison standard explains that it will first find out whether there is a task stack with the same affinity as the started Activity (i.e. taskAffinity, note that the activity in the same application has the same affinity). If so, move the stack as a whole to the foreground and keep the order of the old activity in the stack unchanged, and then the started Activity will be pushed into the stack. If not, a new stack will be built to store the started activity. Note that by default all Activity in the same application have the same taskAffinity.

How's FLAG_ACTIVITY_NEW_TASK?

First of all, I would like to emphasize that the following two LaunchMode startup mode functions have been distinguished:

When an Activity is set to singletask

(1) it does not create a new task stack (TaskId is all the same)

(2) if it already exists in the stack, the onNewIntent method of this instance will be called when the Activity is triggered again, and the new instance will not be recreated.

(3) if there is another Activity on the task stack where this class is located, then all the Activity on it will be out of stack.

When an Activity is set to singleinstance

(1) if there is no instance of this Activity, it creates a new task stack. (the two TaskId are different)

(2) if this instance already exists in the task stack, the onNewIntent method will be called, and no new task stack and instance will be created.

(3) become an independent Taskstack, and have and only you. And always keep an instance off the stack, return the current task first, and then another task

FLAG_ACTIVITY_NEW_TASK personally understands:

By default, all Activity in the same application have the same taskAffinity, that is, the new Activity opened by FLAG_ACTIVITY_NEW_TASK is also in the same task stack (the same task stack as Application). If you want the new Activity to enter a different stack, you need to configure as follows:

/ / pay attention to taskAffinity here

And in this OtherTaskActivityXXX page, if you open any other pages, then all other pages will be pushed into the new task stack.

Thank you for reading this article carefully. I hope the article "how to use flag_activity_new_task" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Task example same article page application affinity two affinity situation method different personal value creative interest again foreground function at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Shulou Tech Info Microsoft Docker