Android的:在声明全局变量成为空当运行应用程序? [英] Android :Declared Global variables becoming null while running the app?

查看:220
本文介绍了Android的:在声明全局变量成为空当运行应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个类。

我是新到Android,我已经在一个类中声明全局变量。和我使用的跨多个活动变量,但这些全局变量变得无效,同时可以运行在低内存设备和版本我使用的测试2.3.6唯一的应用程序

I'm new to android, I have declared global variables in one class. and I'm using that variables across the multiple activities,but these global variables are becoming null while running may app only in low memory devices and version I'm using for testing 2.3.6

我该如何解决这个问题呢?

How can I solve this problem?

推荐答案

我认为你正在创建类的实例中的所有活动各一次。
声明所有变量作为公共静态最后的在那类

I think you are creating instance of that class each time in your all activities. declare all variable as "public static final" in that class

如果您要使用全局变量比你只是code这样你们的活动。

if you want to use that global variable than you just code like this in your activities.

 SQRUtils.downloader = // change which you want//

SQRUtils.mGson = //if you want to change mgson value//

和你每次都可以得到所有数据中的所有类。之后停止该应用程序这个变量将删除。

and you can get all data each time in all class .after stop that application this variable will be delete.

这篇关于Android的:在声明全局变量成为空当运行应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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