登录

android 一个Activity 设置了process 和affinity,主屏task划除问题

这是我一个主应用下得一个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栈的时候会发生当移除任意一个时,另一个进程也被关闭的情况,请问这是什么原因

# Android
巴扎黑巴扎黑2124 天前369 次浏览

全部回复(1) 我要回复

  • 高洛峰

    高洛峰2017-04-17 12:05:28

    以下引用自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"的作用,否则请不要使用这两个参数。同时认真阅读上面链接的内容

    回复
    0
  • 取消回复发送