Android的:在声明全局变量成为空当运行应用程序?空当、应用程序、声明、全局变量

由网友(长眠于你怀)分享简介:我使用这个类。我是新到Android,我已经在一个类中声明全局变量。和我使用的跨多个活动变量,但这些全局变量变得无效,同时可以运行在低内存设备和版本我使用的测试2.3.6唯一的应用程序I'm new to android, I have declared global variables in one class....

我使用这个类。

我是新到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.

阅读全文

相关推荐

最新文章