4

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 there 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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good answer, static singletons are ALSO a good approach. Still, I personally prefer the Application object because it has a well defined lifecycle. There really isn't anything particularly wrong with using it, no drawbacks, just keep the amount of data reasonable (this is for non persistent stuff you need to easily share between components -- for small data using Intents, for large persistent data use the filesystem or the database).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.