Activity的taskAffinities属性

taskAffinities属性用于指定Activity被启动时放到哪一个Task中


在以下两种情况下,taskAffinities会被用到:

1.  如果启动这个Activity的Intent含有 FLAG_ACTIVITY_NEW_TASK标志,且此时系统中还没有这个Activity的实例,那么系统会在新的Task中创建这个Activity,如果这个Activity指定了taskAffinities参数(假设指定了Task X),且taskAffinities指定的Task X在系统中是存在的,那么系统会在Task X中创建这个Activity的实例。


2. 当这个Activity设置了allowTaskReparenting为true时,此时,当taskAffinities指定的Task被移到前端时,这个Activity可以从开始的Task移到taskAffinities指定的Task上。

In this case, the activity can move from the task it starts to the task it has an affinity for, when that task comes to the foreground.

For example, suppose that an activity that reports weather conditions in selected cities is defined as part of a travel application. It has the same affinity as other activities in the same application (the default application affinity) and it allows re-parenting with this attribute. When one of your activities starts the weather reporter activity, it initially belongs to the same task as your activity. However, when the travel application's task comes to the foreground, the weather reporter activity is reassigned to that task and displayed within it.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值