【发布时间】:2011-04-06 18:38:42
【问题描述】:
我有两个应用程序 App-1 和 App-2。 App-2 有一个按钮可以启动 App-1。
需要表现如下:-
- 用户启动 App-1(使用启动器),活动 A、B 和 C 已启动,活动 C 位于活动堆栈的顶部。
- 请注意,App-1 的入口点是活动 A。
- 用户按下主页键。
- 然后用户启动应用程序 App-2。用户选择 App-2 中的按钮来启动 App-1。
-
App-2中按钮的
onClick()有如下代码:-意图 i = new Intent(); i.setAction("com.x.y.z"); //解析到 App-1 的活动 A i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra("x", "y"); 开始活动(i);
在第4步之后,调用活动A的onCreate(),这是很正常的。但是我希望 Android 将整个 Activity Stack 带到前台,因为 App-1 正在运行并且 Android 没有杀死它。(如果我在第 2 步之后启动了 App-1,这也是相同的行为)。
我希望向用户显示活动 C。
如果可以的话,请帮助我。
我尝试将活动 A 设为 singleTask 和 singleInstance。如果我这样做,只有活动 A 被带到前台,这不是我想要的。
App-1 的清单的 sn-p 如下所示:-
<activity android:name=".aa.a"
android:configChanges="orientation|keyboardHidden|locale"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoDisplay"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.x.y.z" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
【问题讨论】:
-
没有。你不能避免 onCreate() 被调用!!您需要在活动流程中找到另一种方式。
-
感谢 Ankit 的回复。我希望你已经完全阅读了这篇文章,尽管我同意它需要大量的耐心和时间。我认为这不是一件很难做到的事情。开发人员可能希望这种行为能够最大限度地减少为模仿相同行为而编写的代码量。我不确定提供这样一个选项有什么困难(当然有一些可以理解的限制)。
标签: android stack android-activity