Android的 - 问题关于singleTask模式 [英] android -- question about singleTask mode

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

问题描述

仰视'任务和返回堆栈指南中的定义启动模式部分之后,我不知道用singleTask。

after looking up the 'Defining launch modes' section of the 'Tasks and Back Stack' guide , I dont understand exactly the behavior of an activity declared with "singleTask".

假设我开始singleTask活性(通过startActivity方法)时,有该活动的铺在底部(根系活力)的后台任务的情况下,

assume that I start a singleTask-activity (via startActivity method ) when there is an instance of that activity laying at the bottom(root activity) of a background task,

如本文所描述的,我使用启动singleTask活性的意图将被传递到该实例,在这种情况下,是否该实例带来本身到其任务和它的任务到前景的顶部,或者仅仅将其任务前景不使自己的工作之上?

as the article describes, the Intent I use to start singleTask-activity will be delivered to the instance, in this case, does the instance bring itself to top of its task and its task to foreground, or just bring its task to foreground without bringing itself to top of its task?

我说清楚了?请帮助!在此先感谢

Do I make myself clear? pls help! thanks in advance

推荐答案

我/我有真正的同样的问题。 在这里阅读答复的计算器,做一些实验,我相信当singleTask活动启动,而它的已经在后台任务,系统将杀死所有其他活动的堆栈的顶部和恢复singleTask活动。

I was/am having the same question actually. After reading replies here on stackoverflow and doing some experiments, I believe that when a singleTask activity is launched while it's already in a background task, the system will kill all other activities at the top of the stack and resume the singleTask activity.

有关肯定,这不是我下了文件,但。

For sure, this is not what I got out of the documentation though.

下面是我的理论:

启动模式:活动答:singleTask,活动B:标准

Launch Modes: Activity A: singleTask , Activity B: standard

实验1

  • 在推出;堆栈:[A]
  • 从发射B:堆栈:[A | B]
  • preSS回家;堆栈:[A | B]
  • 从发射器发射;堆栈:[A]的(的onDestroy被称为基于B onResume()在A)
  • Launch A ; stack: [A]
  • Launch B from A; stack: [A|B]
  • Press home; stack: [A|B]
  • Launch A from launcher; Stack: [A] (onDestroy was called on B before onResume() on A)

实验2

  • 在推出;堆栈:[A]
  • 从发射B:堆栈:[A | B]
  • 从b运行A;堆栈:[A]的(的onDestroy被称为基于B onResume()在A)
  • Launch A ; stack: [A]
  • Launch B from A; stack: [A|B]
  • Launch A from B; stack: [A] (onDestroy was called on B after onResume() on A)

在我的情况,我不得不使用安卓alwaysRetainTaskState =真正的虽然这不是理想的,因为我想将栈后清零,也就是说,10分钟,这一建议是有道理的:

In my case, I had to use android:alwaysRetainTaskState="true" although this is not ideal as I do want the stack to be cleared after, say, 10 minutes as this recommendation makes sense:

如果用户离开一个任务很长   时,系统会清除任务   除了根的所有活动   活动。当用户返回到   任务重,只有根活动   恢复。该系统的行为这种方式,   因为,的延长量之后   时间,用户可能已经放弃了什么   他们在做之前,并   返回到任务开始   新的东西。

If the user leaves a task for a long time, the system clears the task of all activities except the root activity. When the user returns to the task again, only the root activity is restored. The system behaves this way, because, after an extended amount of time, users likely have abandoned what they were doing before and are returning to the task to begin something new.

的<一个href="http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html#Clearing">Tasks和返回堆栈指南。

我希望这可以帮助其他人。

I hope this helps other people.

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

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