应用程序总是从根活动开始,而不是恢复后台状态(已知错误) [英] App always starts fresh from root activity instead of resuming background state (Known Bug)

查看:17
本文介绍了应用程序总是从根活动开始,而不是恢复后台状态(已知错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这些链接中提到的问题:

I am facing exactly the problem mentioned in these links:

http://code.google.com/p/android/问题/详细信息?id=2373

http://groups.google.com/group/android-developers/browse_thread/thread/77aedf6c7daea2ae/da073056831fd8f3?#da073056831fd8f3

http://groups.google.com/group/android-developers/browse_thread/thread/2d88391190be3303?tvc=2

我有一个简单的根活动,包含 LAUNCHER 和 MAIN 意图,没有其他.我开始另一个活动,在清单中没有标志或任何额外的.

I have a simple root activity with the LAUNCHER and MAIN intents and nothing else. I start another activity with has no flags or anything extra in the manifest whatsoever.

我启动应用程序(根活动),然后从那里开始第二个活动.按下主页按钮后,任务进入后台.再次启动应用程序时(从启动器或按住 Home 按钮查看最近的应用程序),它会在现有堆栈的顶部启动一个新的根 Activity 实例.

I launch the app (root activity) and from there start the 2nd activity. On pressing the Home button the task goes to the background. On launching the app again (from Launcher or from holding the Home button for recent apps) it starts a new instance of the root activity on top of the existing stack.

如果我按下后退按钮,新的根"活动将关闭,旧的第二个活动可见,这意味着它会在同一任务中启动根活动,而不是将任务置于前台.

If I press the back button, the new "root" activity closes and the old 2nd activity is visible, which means its launching the root activity in the same task instead of bring the task to the foreground.

为了解决这个问题,我将根 Activity 的启动模式设为 singleTask.现在,当我按下 home 键并再次启动应用程序时,它会清除旧根任务上方的活动并将旧根任务带到前台,而不是将整个旧任务与第二个活动放在最前面.请注意,旧的根任务仍然保留其应用程序状态,这意味着它不是一个新实例,而是更高的活动已被杀死.

To counter this I made the root activity's launch Mode singleTask. Now when I press home and launch the app again, it clears the activities above the old root task and brings the old root task to the foreground instead of just bringing the entire old task with the 2nd activity on top to the front. Note that the old root task still retains its application state, which means it wasn't a new instance, but the the higher activities had been killed.

它甚至出现在从市场上下载的其他应用程序上.手动安装方法对我没有影响,它仍然以相同的方式启动.

It even occurs on other applications downloaded from the market. The manual install method has no effect for me, it still launches the same way.

推荐答案

这是由于用于启动应用程序的意图不同.Eclipse 使用没有操作和类别的意图启动应用程序.Launcher 使用带有 android.intent.action.MAIN 操作和 android.intent.category.LAUNCHER 类别的 Intent 启动应用程序.安装程序会启动一个带有 android.intent.action.MAIN 操作且没有类别的应用.

This is due to the intents being used to start the app being different. Eclipse starts an app using an intent with no action and no category. The Launcher starts an app using an intent with android.intent.action.MAIN action and android.intent.category.LAUNCHER category. The installer starts an app with the android.intent.action.MAIN action and no category.

提交错误的人可能应该将其表述为对 Eclipse 插件的增强请求,因为他们显然希望 Eclipse 能够伪装成启动器并使用与启动器相同的意图启动应用程序.

Whoever submitted the bug should have probably worded it as a request for enhancement to the Eclipse plugin since they apparently want Eclipse to have the ability to pretend to be the launcher and to start apps using the same intent as the launcher.

这篇关于应用程序总是从根活动开始,而不是恢复后台状态(已知错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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