开发者

Using Application class for storing persistent data in Android

开发者 https://www.devze.com 2023-02-08 14:34 出处:网络
I find myself using the Application class a lot to persist user data. These are application wide resources, though I cheat by storing an integer or two sometimes. Are t开发者_运维技巧here any drawback

I find myself using the Application class a lot to persist user data. These are application wide resources, though I cheat by storing an integer or two sometimes. Are t开发者_运维技巧here any drawbacks of doing this? I could not find any documentation which puts a limit on the amount of data that can be stored here.


Well, the documentation to Application says :

There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way.

Also the stuff you put in there goes to the heap(*), which is size constrained (e.g. to 24 MB). If you want to store more data, you should put it in a database or on file system.

*) Technically Android's Dalvik vm may not have a heap, but other ways to store stuff in main memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号