FLAG_ACTIVITY_SINGLE_TOP在Android上的意义意义、FLAG_ACTIVITY_SINGLE_TOP、Android

2023-09-05 04:34:31 作者:非伱 、吥嫁

在意向我可以设置这样的标志,如 FLAG_ACTIVITY_SINGLE_TOP 。有人可以解释我它的意义,因为我只是不明白这一点? =)

In intent I can set such flag as FLAG_ACTIVITY_SINGLE_TOP. Can somebody explain me its meaning, cause I just don't get it? =)

推荐答案

的任务页说,单顶:

如果该活动的一个实​​例已存在于当前任务的顶部,系统路由通过调用其onNewIntent()方法的意图于该实例,而不是创建活动的新实例。该活动可以被实例化多次,每个实例可以属于不同的任务,一个任务可以具有多个实例(但只有当在后面堆栈顶部的活性不活性的现有实例)。

If an instance of the activity already exists at the top of the current task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity. The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances (but only if the the activity at the top of the back stack is not an existing instance of the activity).

例如,假设一个任务的回   堆栈由根系活力A的   活动B,C和D的顶部(在   堆栈是A-B-C-D; D是在上面)。一个   意图到达类型的活动   D.如果D有默认的标准   发射模式下,一个新的实例   一流的推出,堆栈   成为A-B-C-D-D。然而,如果D的   发射模式是singleTop,则   d,现在实例deliverd的   通过onNewIntent意图(),因为   它是在层叠的堆栈的顶部   仍然是A-B-C-D。但是,如果一个意图   到达用于B型的活性,   那么B的一个新实例被添加到   栈中,即使它的发射模式是   singleTop。

For example, suppose a task's back stack consists of root activity A with activities B, C, and D on top (the stack is A-B-C-D; D is on top). An intent arrives for an activity of type D. If D has the default "standard" launch mode, a new instance of the class is launched and the stack becomes A-B-C-D-D. However, if D's launch mode is "singleTop", the existing instance of D is deliverd the intent through onNewIntent(), because it's at the top of the stack—the stack remains A-B-C-D. However, if an intent arrives for an activity of type B, then a new instance of B is added to the stack, even if its launch mode is "singleTop".