android 一个Activity 设置了process 和affinity,主屏task划除问题
巴扎黑
巴扎黑 2017-04-17 12:03:28
[Android讨论组]

这是我一个主应用下得一个Activity设置:

  <activity
            android:name=".activity.WebViewActivity"
            android:launchMode="singleInstance"
            android:process="com.test.webivew"
            android:configChanges="orientation|screenSize"
            android:taskAffinity="com.lydiabox.webView"

我打开主应用,然后打开这个Activity,我按home回到主界面,看最近打开应用,这是会出现两个任务栈,在移除主应用task栈或者这个activity Task栈的时候会发生当移除任意一个时,另一个进程也被关闭的情况,请问这是什么原因

巴扎黑
巴扎黑

全部回复(1)
高洛峰

以下引用自http://developer.android.com/guide/topics/manifest/activity-element.html

The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task.

如果你不想出现2个task那么请移除你的android:launchMode="singleInstance"

关于移除一个另一个也会关闭的情况:
所有的task都是从主应用打开的,你关闭主应用,所有的应该会同时关闭了
另一个情况,关闭这个activity task也会关闭的情况,应为你设定的process为android:process="com.test.webivew",会关闭这个进程,你查看下是不是你application的process也设置为com.test.webivew

最后提醒以下,除非你明确知道android:launchMode="singleInstance"android:taskAffinity="com.lydiabox.webView"的作用,否则请不要使用这两个参数。同时认真阅读上面链接的内容

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号