Android中的根活动是什么? [英] What is the root activity in android?

查看:60
本文介绍了Android中的根活动是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://developer.android.com/guide/topics/manifest/activity-element.html

android:alwaysRetainTaskState

活动将始终由系统维护活动所在的任务的状态.如果是,则为"false".如果在某些情况下允许系统将任务重置为其初始状态... 此属性仅对任务的根活动有意义;其他所有活动都将忽略它.

android:alwaysRetainTaskState

Whether or not the state of the task that the activity is in will always be maintained by the system — "true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain situations...This attribute is meaningful only for the root activity of a task; it's ignored for all other activities.

那么根活动到底是什么意思?

So what does root activity mean exactly?

根活动是否有意义

"使用 android.intent.action.MAIN android.intent.category.LAUNCHER 定义的活动"

"Activity that is defined with android.intent.action.MAIN and android.intent.category.LAUNCHER"

或者只是

在此确切时刻碰巧处于后排堆栈底部的任何活动"

"whatever activity that happens to be at the bottom of the back stack at this exact moment"

推荐答案

通常是的,使用 android.intent.action.MAIN android.intent.category定义的活动.LAUNCHER 将是任务堆栈的根活动.

In general Yes, the activity that is defined with android.intent.action.MAIN and android.intent.category.LAUNCHER will be the root activity of the task stack.

但是只有很少的意图标志,我们可以将任何活动作为根活动.例如我的堆栈A-> B-> C中有三个活动,现在我想通过设置这些意图标志将活动D作为根活动启动 FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK 活动D将是根活动.

But with few intent flags we can make any any activity as root activity. e.g. I have three activities in my stack A->B->C and now I want to launch activity D as a root activity by setting these intent flags FLAG_ACTIVITY_CLEAR_TASK|FLAG_ACTIVITY_NEW_TASK activity D will be root activity.

FLAG_ACTIVITY_CLEAR_TASK :如果在传递给Context.startActivity()的Intent中进行设置,则此标志将导致在活动开始之前清除与该活动关联的所有现有任务.也就是说,该活动成为原本为空的任务的新根,并且所有旧活动都已完成.只能与FLAG_ACTIVITY_NEW_TASK结合使用.

FLAG_ACTIVITY_CLEAR_TASK: If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

这篇关于Android中的根活动是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆