强制关闭不退出的Andr​​oid应用程序,而不是将打开非常错误状态previous活动 [英] Force close doesn't exit android application, instead opens a previous activity in very buggy state

查看:134
本文介绍了强制关闭不退出的Andr​​oid应用程序,而不是将打开非常错误状态previous活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我遇到的问题是我的运行Android应用的时候,如果我碰上了强制关闭的错误或在调试模式下一个断点,然后preSS'一站式'暂停应用程序,应用程序不退出,而不是在我的活动堆栈中的第一个活动是打开,但它是在一个非常错误的状态。该活动是书籍的图书馆,当它被用力闭市后或停止,所有的书都不见了用户,选择菜单上的标签都没有了(虽然图标仍然存在)打开,几乎所有的操作导致一个强制关闭。

The problem that I'm having is when running my android app, if I run into a force close error or pause the application with a breakpoint in debug mode and then press 'stop', the app doesn't quit, instead the first activity on my activity stack is opened but it is in a very buggy state. The activity is a library of books and when it is opened after the force close or by stopping, all of the users books are gone, the labels on the options menu are gone (although the icons are still there) and almost any action results in a force close.

所以基本上我不知道为什么停在调试模式下的应用程序,或者运行到一个强制关闭不关闭整个应用程序,而是打开了第一个活动在非常错误的状态。

So basically I'm wondering why stopping the application in debug mode, or running into a force close doesn't shut down the whole application and instead opens the first activity in a very buggy state.

我不能给出具体的code,因为关闭力只发生过一次,我没有得到的堆栈跟踪。我意识到这是一个非常通用的问题,我的理解,如果它是信息太少,走下车的我只是想看看是否有人遇到了类似的事情。

I can't give specific code because the force close only happened once and I didn't get the stack trace. I realize this is a very generic question and I understand if it's too little information to go off of I just wanted to see if anyone else had run into something similar.

编辑:这好像强制关闭只是关闭当前的活动,并试图打开堆栈上的previous活动。但是不知何故我的应用程序上下文被破坏掉了所以当previous活动打开,会在应用程序上下文的信息,如用户的图书馆的书,里面空空如也。

It seems as though force close just closes the current activity and tries to open the previous activity on the stack. However somehow my application context is getting destroyed so when the previous activity opens and looks for information in the application context, such as books in the user's library, there is nothing there.

推荐答案

当你遇到一个强制关闭,您的应用程序的过程中被杀害。如果你的活动堆栈有崩溃的一个在后面的活动,它在一个新的进程将重新启动。当进程死掉,所以没有应用程序上下文。新的过程创建一个新的应用程序上下文,这就是为什么你没有在那里看到你的数据。

When you run into a force-close, your app's process is killed. If your activity stack had an activity behind the one that crashed, it is restarted in a new process. When the process dies, so does the application context. The new process creates a new application context, which is why you're not seeing your data in there.

请参阅的http://groups.google.com/group/android-developers/browse_thread/thread/b274cfa64b17f535?pli=1关于此的讨论。

See http://groups.google.com/group/android-developers/browse_thread/thread/b274cfa64b17f535?pli=1 for a discussion on this.

要满足您的特定问题的方法是在你的应用程序对象添加一个标志,您明确设置为true共享加载数据后。然后,您可以检查这个标志在活动的onCreate()来确认数据是可用的。如果该标志是假的,你可以调用finish()

One way to address your specific problem is to add a flag in your Application object, that you explicitly set to true after your shared data is loaded. You can then check for this flag in your Activity's onCreate() to confirm that the data is available. If the flag is false, you can call finish()

这篇关于强制关闭不退出的Andr​​oid应用程序,而不是将打开非常错误状态previous活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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