android app 如何存储数据作为全局变量, 在各个activity 中调用?
ringa_lee
ringa_lee 2017-04-17 13:46:55
0
2
572

android app 如何存储数据作为全局变量, 在各个activity 中调用? 我在开发过程中用的是单例模式, 但是单例模式会出现过一段时间销毁的问题, 导致应用在开始使用正常情况下, 过一段时间久出现了空指针的闪退. 求教大牛, 你们一般是在处理全局变量.

ringa_lee
ringa_lee

ringa_lee

reply all(2)
刘奇

Generally, object variables placed in a class are not very stable. If you need to record content in the memory and require this data to be used in other activities, it is best not to put it in other classes. It should be defined When a class is destroyed is undefined. So if you need something recorded in memory, put it in the Application class.
In addition, if persistence is required, use database, file, SharedPreference.

迷茫

Put frequently used variables in the Application. If persistence is required, put them in the database or SharedPreference.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template