【发布时间】:2011-10-02 17:50:01
【问题描述】:
我认为 App Manager 在安装后以错误的方式运行我的应用程序。它在其任务中运行我的应用程序。当我按下 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。按 Home。按 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。按 Home。按 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>
【问题讨论】: