I'm building a new android app which uses data from a server through different activities.
currently I have 2 activities, the main one connects to the server and creates the singleton object (which is shared for all activities) using the data from the server.
obviously I have an instance of the data held in the singleton class, and get the object from a static method.
I know that this is not the best way to implement a shared data between activities - I can pass them through intents (but I'm planning to create more 3-4 activities which uses the same data so why to pass them when you can have them in a static context global for the app).
What this implementation got me into is this problem: when the user switches to another app at the second activity, and my app stays for some time on background, android frees the memory used by the app, and when returning to it, I get null pointer exception when using one of the fields of the singleton object!
I solved the problem by returning to the main activity (if the object is null) to recreate the data, but this makes the activity reconnect every time it's destroyed (it's not optimal since the data on the server doesn't change much). I know that I have to save the server data onDestroy and to recreate the object every time I return to the activity but this must happen on every activity, and the data is about 4-5KB meaning it needs to be written to a file, and parsing it takes time (accessing phones SD card).
I'm starting to think on using Parcelable object to share the data through intents - I think android can save and restore the data of the intents automatically and in a optimal way. (ref: http://bimbim.in/post/2010/09/27/Android-Passing-object-from-one-activity-to-another.aspx)
The question is, will intents solve my problem? Is there another ways? Better, faster ways?
Thanx!