Static variable in Application class returns null when accessing it

百般思念 提交于 2019-12-10 12:26:44

问题


I am defining a variable in application class like this

public static ResultReceiver myResultReceiver = 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.


回答1:


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.




回答2:


@Ahmed Hegazy is correct. Problem was I have added android:process in manifest to kill intent service because of that I am not able to access.



来源:https://stackoverflow.com/questions/31519217/static-variable-in-application-class-returns-null-when-accessing-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!