保存在android的活动状态时,主页按钮pressed [英] Save activity state in android when home button pressed

查看:81
本文介绍了保存在android的活动状态时,主页按钮pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相关的home键的问题。当我preSS home键的当前活动被隐藏起来,但是当我再次启动可执行文件,它开始在第一个屏幕。我已经overidden所有方法(的onSaveInstanceState,在onPause,的onStop onResume),但仍存在问题。什么是正确的方式来处理呢?

I am having an issue related to the home key. When I press the home key the current activity gets hidden, but when I start the executable again, it starts at the first screen. I have overidden all methods (onSaveInstanceState, onPause, onStop onResume) but there are still issues. What is the right way to handle this?

当我preSS home键,我存储在数据库中的窗口小部件的状况,当我再次启动exectable我检查了数据库的状态,并开始被保存在用户pressed家新意图按钮。这是正确的方式做到这一点,当用户不一样的,再次为我所面临的问题presses后退按钮,已经有在活动栈提供意向。

When I press the home button I am storing the widget state in a database and when I again start the exectable I am checking the database state and starting the new Intent that was saved when user pressed the home button. Is this the right way to do that, as I am facing the problem when user does the same and again presses the back button, there is already on intent available in the activity stack.

推荐答案

我已经竭尽全力来应付这一奇怪的行为进行了一个多月,但我终于找到了通过试验和错误的解释。

I've struggled with this odd behavior for more than a month but I finally found out the explanation by trial and error.

此行​​为,当您从Eclipse的应用程序发生时,通过命令行或如果您打开按钮安装(而不是完成按钮),应用程序和preSS为您安装它之后立即启动应用程序。

This behavior happens when you start your application from Eclipse, from command line or if you install an application and press on the Open button (instead of the Done button) to start the application right after you installed it.

如果在这些情形之一的,你开始你的apllication,去活动1,然后到活动2,preSS HOME按钮,然后preSS应用程序图标,它会打开活动1的新实例。不要把我的话。只要preSS回来看看,它让你到你的活性2,你离开的时候你pressed HOME。

If in one of those cases, you start your apllication, go to Activity1 and then to Activity 2, press HOME button and then press the application icon, it will open a new instance of Activity1. Don't take my word for it. Just press BACK and see that it gets you to your Activity2 that you left when you pressed HOME.

看来,发射活动是穿不上的活动堆栈如果应用程序开始的上方,这就是为什么它在应用程序的堆栈当前的活动之上创建的发射活动的一个新实例提到的那些方式之一。这在我看来就像一个错误。

It seems that the launcher activity is not put on the activity stack if the application is started in one of those ways mentioned above so that's why it creates a new instance of the launcher activity on top of the current activities in the application's stack. This looks to me like a bug.

因此​​,解决方法是退出应用程序,它第一次是从Eclipse或者命令行或打开按钮等开始,以pressing后退按钮,当需要多次,然后输入应用程序再次。从此,该行为将被预期。

So, the workaround would be to exit the application, the first time it was started from Eclipse or command line or Open button etc., by pressing the BACK button as many times as needed, and then enter the application again. From then on, the behavior will be as expected.

这篇关于保存在android的活动状态时,主页按钮pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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