How to use global class variables in android

后端 未结 4 924
粉色の甜心
粉色の甜心 2021-01-26 09:12

Hi I am doing one app here. I\'m using global class varibles. It\'s working well, but if I\'m using more globalclass variables I\'m getting memory exceptions some times.

4条回答
  •  无人及你
    2021-01-26 09:57

    Take a look at the post Singletons vs. Application Context in Android?

    There are a lot of discussion about Singletons vs Application objects in the forum. I'm personally inclined to Application object with properties. If you dont want to keep in memory a lot of objects use a LruCache (there is a pre v11 implementation in the compatibility package) to low your memory requirements.

    Take into account you will eat the same amount of memory using Singletons than using the Application object, all objects will be keep in memory until you free them (remove any refrence to them and let the GC purge them from memory).

提交回复
热议问题