应用程序上下文变量值丢失应用程序错误 [英] Value of Application Context Variables Lost on Application Error

查看:156
本文介绍了应用程序上下文变量值丢失应用程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我的应用程序遇到一个错误,我的应用程序上下文变量的值也被重新初始化为原始值(不更新的值)。从我的理解为主,发生这种情况是因为应用程序被重新创建。

如何保存,当出现应用程序错误恢复我的应用程序上下文变量的值?我会很高兴,如果你能给的事情是如何在我的应用程序的后台运行,当它遇到错误的更详细的解释。

注:我读了这个解决方案之一是使用共享preferences。然而,即使当应用程序死共享preferences保存数据。我不希望保存数据时,该应用程序是死的。我只想保存数据时,该应用程序是活的或背景。


解决方案

  我

如何保存和恢复我的应用程序上下文变量的值,当出现应用程序错误?


首先,没有一个未处理的异常。

二,不依赖于静态数据成员或自定义应用子类的实例。在很多情况中,你的程序将被终止,这些值消失。他们应该被用于永久内容的内存缓存,并没有别的。

有时,未处理的异常是真正的意外,但这些应该是罕见的,通常依赖于特定的设备(例如,跑出的存储空间)。一切重新presents的错误在你的应用程序,您必须修复的错误。

I noticed that when my application encounters an error, the value of my application context variables are also reinitialized to its original value (not the updated value). Based from my understanding, this happened because the application was recreated.

How can I save and restore the values of my application context variables when an application error occurs? I'll also be glad if you could give a more detailed explanation on how things are working on the background of my application when it encounters an error.

Note: I read that one of the solution for this is by using SharedPreferences. However, SharedPreferences saves the data even when the application is dead. I don't want to save the data when the application is dead. I only want to save the data when the application is alive or on background.

解决方案

How can I save and restore the values of my application context variables when an application error occurs?

First, don't have an unhandled exception.

Second, don't rely on static data members or custom Application subclass instances. There are many scenarios in which your process will be terminated and those values go away. They should be used for an in-memory cache of persistent content, and little else.

Sometimes, unhandled exceptions are truly unexpected, but these should be infrequent and usually tied to specific devices (e.g., ran out of storage space). Everything else represents a bug in your app, and you must fix the bugs.

这篇关于应用程序上下文变量值丢失应用程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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