关于Android launchmode" singleTask" [英] About android launchmode "singleTask"

查看:133
本文介绍了关于Android launchmode" singleTask"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了Android开发者指南和网上一些文章,我仍然扑朔迷离关于 singleTask launchmode 。让我们举一个例子:

用户推出的App1的,机器人会启动新任务。假设App1的继以便创建活动:

  ActivityA  - > ActivityB  - > ActivityC
 

这是任务1看起来怎么样。

然后用户单击主页BUTTOM并选择启动App2的,所以任务1云在后台和Android开始一个新的任务:任务2,用户做了:

  ActivityD  - > ActivityE
 

现在可以说 ActivityE 尝试启动 ActivityB ActivityB 的launchmode singleTask

我的理解是,任务1来再次前端和TASK2被切换到后台。而任务1现在看起来是这样的:

  ActivityA  - > ActivityB
 

这意味着:

  1. ActivityC 将会从任务1中删除,并ActivityB成为顶端活动。

  2. 如果现在用户点击后退按钮,他会来 ActivityA 任务1,而不是回到 ActivityE

我说得对不对?

感谢

解决方案
  

该ActivityC将会从任务1中删除,并ActivityB成为顶端活动。

是的,你是对的...

ActivityC将从即ActivityC的的onDestroy方法删除将被调用。用户再次启动任务1因此,当时,ActivityB示而非ActivityC

已创建2任务(项目),并上载相同@ SendSpace 。试试吧...

如果你看一下机器人<一href="http://developer.android.com/guide/topics/manifest/activity-element.html#lmode">documentation它说:

AsingleTask活动允许的其他活动是其任务的一部分。它总是在其工作的根本,但其他活动(不一定是标准和singleTop的活动),可以发射成的任务。

这意味着当您单击全部activites以上的单任务活动的主页按钮(在你的情况是ActivityB)都是从栈中删除。

在示例应用程序的我给你前面,如果你只是运行项目AndroidTest,然后单击日志中的home键,你可以看到,第二个活动放在暂停,当你再次启动它的最近应用程序的列表中的第二个活动被销毁。

在一个塞纳里奥其中活动的上述单一实例activites(ActivityB)不会从返回堆栈取出,另一个应用程序请求该活性(ActivityB)它可能不被显示并且意图可以被丢弃。但是,这有发生,因为用户将不得不preSS的主页按钮,但目前的任务\ APP在BackStack他还没来得及浏览到另一个任务\ APP的extreamly机会较少。

因此​​,警告

其它模式 - singleTask和singleInstance - 不适合于大多数的应用,因为它们导致的相互作用模型,很可能是不熟悉的用户和从其他大多数应用中是非常不同的

我希望这能解决您的疑问。

I read the android developer guide and some articles in internet, I'm still confusing about the singleTask launchmode. Lets take an example:

User launch the App1, android starts a new task. Assume the App1 creates activities in follow order:

ActivityA -> ActivityB -> ActivityC

That's how task1 looks like.

Then user click the home buttom and choose to launch App2, so task1 goes in background and android start a new task: task2, user does something:

ActivityD -> ActivityE

now lets say ActivityE try to start ActivityB , and ActivityB has the launchmode singleTask.

What I understand is that task1 comes to frontend again and task2 goes to background. And task1 looks now like this:

ActivityA -> ActivityB

Which means:

  1. The ActivityC will be removed from task1 and ActivityB becomes to the top Activity.

  2. If user now click on "Back" button, he will come to ActivityA of task1 instead of back to ActivityE of task2

Am I right?

Thanks

解决方案

The ActivityC will be removed from task1 and ActivityB becomes to the top Activity.

Yes you are Right...

ActivityC will be removed from i.e. the onDestroy method of the ActivityC will be called. Hence when the user launches Task 1 again, the ActivityB is shown rather than ActivityC.

Have created 2 Tasks (Projects) and uploaded the same @ SendSpace. Try it out...

If you look at androids documentation it says

" 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."

Which means that when you click the home button all the activites above the single task activity (which in your case is ActivityB) are removed from the stack.

In the sample app's i had given you earlier if you just run the project "AndroidTest" and click the home button in the logs you can see that the 2nd Activity is put on Pause, and when you launch it again from the "Recent App's" list the 2nd Activity is Destroyed.

In a senario where the Activity's above the Single Instance activites (ActivityB) are not removed from the Back Stack, and another application request this Activity (ActivityB) it may not be shown and the intent may be dropped. But this has extreamly less chances of happening because the user will have to press the Home button and but the current Task\App in the BackStack before he could navigate to another Task\App.

Hence the warning

The other modes — singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications.

I hope this solves your doubts.

这篇关于关于Android launchmode&QUOT; singleTask&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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