在应用程序范围的静态变量是空的应用程序崩溃时 [英] static variables in application scope are null when app crashes

查看:169
本文介绍了在应用程序范围的静态变量是空的应用程序崩溃时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,扩展应用程序类。现在,在应用程序的某个地方一些静态变量,如果碰撞发生那么这些正在成为空为什么它是如此。

I have some static variables in a class which extending the Application class .Now, somewhere in app ,if crash takes place then these are becoming null why it is so.

我可以明确地说喜欢,我声明在应用子类这两个变量和其他Java类初始化时发生崩溃,这些成为null.my应用要求登录只有这两个应该初始化后。

can i say clearly like, I am declaring those two variables in Application sub class and initializing in other java class when crash occurs these becoming null.my app requirement is after login only those two should be initialized.

有关的任​​何答案/建议在此先感谢

For any answer/advice Thanks in advance

推荐答案

静态变量与类相关联,并且只要类是,他们将活在记忆里(这就不存在了,一旦你的应用程序终止或一旦类被卸载,请参阅了解更多信息)。因此,您的静态变量起停止存在,你的应用程序崩溃,并且再次拿起他们的价值观为

Static variables are associated with a class and they will live as long as the class is in the memory(which ceases to exist once your application terminates or once the class gets unloaded, read this for further information). Hence, your static variables cease to exist when your application crashes, and again take up their values as null.

有关这些变量的持久值存储,选择共享preferences

For persistent value storage of these variables, opt for SharedPreferences.

了解更多关于共享preferences 这里。和例如的一起工作。

Read more about SharedPreferences here. And an example to work with.

这篇关于在应用程序范围的静态变量是空的应用程序崩溃时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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