Reputation: 2722
I use several maps to cache data in my activity. And when I manipulate back to the activity the maps have been collected by the GC and throws out a nullpoint exception. So I should save these maps to avoid it.The problem is how can I do? just implement pacerable and put these data into the bundle? There is any other way to sovle this problem with graceful? Thanks for your replying with any help.
Upvotes: 0
Views: 232
Reputation: 1006614
If these are truly caches, simply reload the data from their original source as needed. That's what a "cache" is for -- optimizing access for a short period of time, with something else (e.g., a local file) being the backing store.
You can choose the lifespan for your caches. Right now, they appear to be part of a single activity, which means if that activity is destroyed, the cache is destroyed. That may be appropriate, or it may not. You could also make the caches live for your entire process lifetime by making them static data members of some class. You need to be very careful that you do not introduce memory leaks this way, causing you to run out of heap space. But, in this case, the caches will live as long as the process does.
However, eventually, the process will be terminated (e.g., user presses HOME and does not return to your application for a substantial period of time). That is why you need to be able to reload your caches from their original source as needed.
Upvotes: 4