Is it safe to use static class variables in an android application

后端 未结 4 1014
遇见更好的自我
遇见更好的自我 2021-01-19 01:52

I am aware of the technique of extending the Application class to provide global storage. However in my case I am writing a class for a library function, so do not wish to f

4条回答
  •  青春惊慌失措
    2021-01-19 02:33

    You seem to have a deep misconception of how classes work.

    Even if two classes are in the same package in two separate apps (by default) those apps run on separate VMs (i.e., processes). They literally have nothing to do with each other (as it should be, since otherwise you might get cross-app name collisions which is unacceptable).

    What you're looking for is not a way to use static variables but a way to do inter-process communication (IPC). Android's Services are ideal for this, though there is a bit of a steep learning curve there.

提交回复
热议问题