Android的生命周期 - ActivityManager杀死进程 - >当异常返回背景 [英] Android Lifecycle - ActivityManager kills process -> Exception when returning from background

查看:226
本文介绍了Android的生命周期 - ActivityManager杀死进程 - >当异常返回背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很无聊的问题。当我的应用程序被切换到后台,有时这个过程被打死的LogCat中所示:

I'm having a very boring problem. When my app goes to background, sometimes the process is killed as the LogCat shows:

INFO/ActivityManager(187): Low Memory: No more background processes.
INFO/ActivityManager(187): Process com.app.myapp (pid 20681) has died.
INFO/WindowManager(187): WIN DEATH: Window{40592708 com.app.myapp/app.myapp.dashboard.Dashboard paused=false}
ERROR/InputDispatcher(187): channel '408b1d40 app.myapp/app.myapp.menus.products.Promotions (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
ERROR/InputDispatcher(187): channel '408b1d40 app.myapp/app.myapp.menus.products.Promotions (server)' ~ Channel is unrecoverably broken and will be disposed!
INFO/WindowManager(187): WIN DEATH: Window{408b1d40 app.myapp/app.myapp.menus.products.Promotions paused=false}
INFO/ActivityManager(187): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 cmp=app.myapp/.Main } from pid 187
INFO/ActivityManager(187): Start proc app.myapp for activity app.myapp/.menus.products.Promotions: pid=20721 uid=10062 gids={3003, 1015}

当我再尝试返回到应用程序,通过任务切换(长preSS家),它试图返回到最后打开的活动......和崩溃。

When i then try to return to the app, via task switcher (long press home) it tries to return to the last opened activity... and crashes.

为什么不是从头开,开盘主要因为整个应用程序被关闭了?

Why doesn't it open from scratch, opening Main as the whole app was closed?

错误/ InputDispatcher误差修改并不总是出现。

The ERROR/InputDispatcher erros do not always appear.

更新:

问题是...应用程序恢复,但已下载(作为一个HashMap)中的对象都没有......所以,当我访问这些....我有问题......

The problem is... the Application is restored, but the objects in it that were downloaded (as a hashmap) aren't... so when i access them.... i have "problems"...

更新2:

我有管理由上BaseActivity verifing上的onCreate(由所有其他扩展),如果应用程序中包含我所需要的数据,或者如果它是空值(在这种情况下,重新启动应用程序)来解决这个问题。

I've manage to fix the problem by verifing on onCreate on BaseActivity (that is extended by every other) if the Application contains the data I need or if it's null (in this case it restarts the app).

有没有更好的解决方案,或者至少一种方式说,如果应用程序被杀死了,我想申请重新启动设备?

Is there a more elegant solution, or at least a way to say to the device that if the application is killed, i want the application to be restarted?

这个链接有助于理解这个问题......,知道那里是如何从应用商店中的数据没有明确的答案:的 Android的:?如何声明全局变量

This links helped understand the problem... and knowing there is no clear answer for how to store the data from Application: Android: How to declare global variables?

更新3:

所以,我特别问了如何保存应用程序数据的正确的问题。这可以帮助那些有同样的问题:<一href="http://stackoverflow.com/questions/6063550/android-best-way-to-save-data-stored-in-application-singleton-class">Android:保存存储在应用单例类数据的最佳方式

So I asked a question specifically of how to save Application data correctly. This may help those with the same question: Android: Best way to save data stored in Application Singleton Class

推荐答案

据我ubderstand它会回来,因为用户没有关闭应用程序。 A到:该活动是不是访问包数据是一个从开放活动通过呢?如果是这样,你可能想看看捆绑的实例保存和恢复,你可以实现,解决了应用程序回来入上午无效状态前台功能。

As far as I ubderstand it goes back because the user didn't close the application. A though: are you accessing bundle data in that activity that's passed from the opening activity? If so you may want to look into the bundle instance saving and restoration functions that you can implement to solve the app coming back into the foreground in am invalid state.

修改为清楚起见:应用程序恢复到previous状态,因为它被打死操作系统因内存不足而它的背景。当任务切换回它还原到previous状态和无效/不存在捆绑的数据可能会导致该活动恢复时崩溃。

Edit for clarity: the application is restored to its previous state because it was killed by the OS due to low memory while it's in the background. Upon task switching back it's restored to that previous state and invalid / non-existent bundle data may be causing the crash when that activity is resumed.

这篇关于Android的生命周期 - ActivityManager杀死进程 - &GT;当异常返回背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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