安卓:启动模式“单一实例” [英] Android: Launch mode 'single instance'

查看:137
本文介绍了安卓:启动模式“单一实例”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历的单个实例文档,并尝试一些样品。 在我的示例之一,我有三个活动:A-> B-> C, 其中B拥有的安卓launchMode =singleInstance的清单中。活动A和C的默认启动模式。

I was going through the documentation for single instance and was trying out few samples. In one of my sample I have three activities: A->B->C , where B has android:launchMode="singleInstance" in manifest. Activity A and C has default launch mode.

方案:

通过A和B(即A-> B-> C)导航到C之后,返回键$ P $从活动çPSS需要到活动A(C-> A),但后退按钮preSS活动A不退出程序,而带来的b活动,以正面,然后背扣$ P $从b活动PSS退出应用程序。

After navigating to C via A and B (i.e A->B->C), back button press from Activity C takes to Activity A (C->A), but back button press from Activity A does not quit the app, rather brings the Activity B to front, then back button press from Activity B quits the app.

问题

为什么b活动涉及到前台时,后退按钮从活动一pssed $ P $?

其他情况:

Similarliy,从活动Ç如果用户​​presses设备Home键,然后回来用久置preSS的应用程序,C停留在前台。但是,后退按钮preSS流接受C-> A - >退出应用程序。这次活动B不来前景。

Similarliy, from Activity C if user presses device Home button, and come back the app by long home press, C stays in foreground. But back button press flow takes C-> A -> quits the app. This time Activity B does not come to foreground.

推荐答案

从导航后的 A-> B 你有2个任务:第一个包含 A 的第二个包含的 B B 在顶部和 A 低于这一点。

After navigating from A->B you have 2 tasks: The first one contains A, the second one contains B. B is on top and A is below that.

现在从B-航行时>çAndroid的推出活动C进入任务包含A(它不能启动它到含B中的任务,因为B被定义为singleInstance,所以它启动它到具有相同的taskAffinity,在这种情况下,含有A的任务)的任务。要做到这一点,Android的使含有A到前面的任务。现在你有两个任务:含有A和C在面前的任务,而第二个包含低于使得b

Now when navigating from B->C Android launches activity C into the task containing A (it cannot launch it into the task containing B because B is defined as "singleInstance", so it launches it into a task that has the same "taskAffinity", in this case the task containing A). To do that, Android brings the task containing A to the front. Now you have 2 tasks: The task containing A and C in the front, and the second one containing B below that.

现在你preSS BACK键,而完成活动C和返回到低于在任务活动,即C.你仍然有2个任务:一种含下在前面,含硼一个下面这一点。

Now you press the BACK key, which finishes activity C and returns to the activity below that in the task, namely C. You still have 2 tasks: The one containing C in the front, and the one containing B below that.

现在你又preSS返回键。这就完成活动A(从而完成了举行的任务),并带来了在任务堆栈中的previous任务前,即含有B.你现在有1任务的任务:包含B中的任务。

Now you press the BACK key again. This finishes activity A (and thereby finishes the task that held A) and brings the previous task in the task stack to the front, namely the task containing B. You now have 1 task: the task containing B.

在您的另一种情况,从浏览后的 A-> B-> C ,你开始2个任务:含有A和C在前面的任务,第二个包含低于B点。

In your other scenario, after navigating from A->B->C, you start with 2 tasks: The task containing A and C in the front, and the second one containing B below that.

现在你preSS HOME键。现在你说你的回来到应用程序通过长preSS。这是不完全正确的。你不能回来到应用程序。只能回归到一个任务。但是,你有2个不同的任务:如果你这样做很长的preSS你应该看到2个任务。他们可能有相同的图标(除非你提供b活动不同的图标),所以你可能无法区分它们。如果您选择包含A和C的任务,那么这个任务将被带到前面,顶部的活动℃。如果你现在preSS BACK键,活动Ç将完成和其下的活动,活动A将被显示。现在如果你重新preSS BACK键,活动A将被完成,你将返回到主屏幕。该含硼任务仍然是在近期任务列表中,但它不再是任务堆栈在你的其他任务,因为当你preSS在 HOME键就好像回到零。你从头再来。您没有活动的任务,因此,所有的任务都成一排,它们不是在一堆栈和没有等级

Now you press the HOME button. You now say that you "come back to the app by long press". This isn't exactly correct. You can't "come back to the app". You can only "return to a task". But you've got 2 different tasks: If you do a long press you should see the 2 tasks. They probably have the same icon (unless you've provided a different icon for activity B) so you may not be able to tell them apart. If you select the task that contains A and C, then that task will be brought to the front with activity C on top. If you now press the BACK key, activity C will finish and the activity under it, activity A will be shown. If you now press the BACK key again, activity A will be finished and you will be returned to the HOME screen. The task containing B is still in the list of recent tasks, but it is no longer in the task stack under your other task because when you press the HOME button it is like going back to zero. You start all over again. You have no active tasks, so all tasks are in a row, they aren't in a stack and there is no hierarchy.

此外,在你的问题,你用这个短语的退出应用程序。这也并非完全正确。一个返回按钮preSS所做的唯一一件事就是完成当前的活动。如果当前活动是在任务中的唯一活性,也完成这项任务。但是,它并没有退出程序。特别是在你的情况,因为你的应用程序实际存在于两个独立的任务。

Also, in your question you use the phrase "quits the app". This also isn't quite correct. The only thing that a BACK button press does is to finish the current activity. If the current activity is the only activity in a task, it also finishes that task. However, it doesn't "quit the app". Especially in your case, since your "app" actually exists in 2 separate tasks.

希望这是显而易见的。

这篇关于安卓:启动模式“单一实例”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆