访问它的Application类中的静态变量返回null [英] Static variable in Application class returns null when accessing it

查看:100
本文介绍了访问它的Application类中的静态变量返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样的应用程序类中定义一个变量

I am defining a variable in application class like this

public static ResultReceiver myResultReceiver = null;

在某些活动中,我将扩展ResultReceiver并将其分配给myResultReceiver,在活动的stop()中将其设置为null. 虽然myResultReceiver还不为null,但是当我从intentservice中访问它时,它还是为null.到今天为止,代码运行良好.

In some activities I am extending ResultReceiver and assigning to myResultReceiver, in stop() of activities I am making it null. Though myResultReceiver is not null yet when I access it from an intentservice it is null. The code was working fine till today.

推荐答案

也许是,也许您正在使用

May be, just may be you have the service on another process using the android:process or android:isolatedProcess attribute. If so, that makes a separate isolated new process which the Service runs in and it's impossible to read any data from another process even static variables except using IPC or SharedPreferences.

如果不需要该属性,则将其删除并避免麻烦.

If you don't need the attribute then remove it and save yourself from the hassle.

这篇关于访问它的Application类中的静态变量返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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