1
我认为应用程序管理器在安装后以错误的方式运行我的应用程序。它运行我的应用程序的任务。当我按HOME并按应用程序图标时,我用我的应用程序运行第二个任务。如何强制应用程序总是在自己的任务中运行?
我测试了它。我做了两个应用程序App1,App2。 App2有两个活动A和B.App1以最简单的方式运行App2。
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("org.app2.test", "org.app2.test.Screen1"));
测试1.运行App1。 App1运行App2活动A.活动A运行活动B.按主页。按App2图标。你可以看到App2的活动A.(错误,我们必须使用App2的任务)
我改变了启动App2的代码。
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName("org.app2.test", "org.app2.test.Screen1"));
测试2.运行App1。 App1运行App2活动A.活动A运行活动B.按主页。按App2图标。您可以看到App2的活动B.(确定)
如何更改App2清单并强制App2始终在其自己的任务中运行?
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Screen1"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Screen2">
<intent-filter>
<action android:name="org.app2.test.screen2" />
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</activity>
</application>