tags:

views:

257

answers:

3

Hi,

My android app fetches a JSON structure from the net. It's somewhat large, maybe 2,000 characters in length. I need to store it away when my app gets killed so I can recover it quickly. I've tried saving it to an sqlite database, but that takes about 400ms, kind of long. I wonder if it's bad practice to just dump it into the save bundle:

protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    String jsonString = myObject.toString();
    outState.put("test", jsonString);
}

or are we really only supposed to be putting the smallest of items in bundles?

Thanks

A: 

how about SharedPreferences ?

David Hedlund
I could use that too, and actually my data is more like 60,000 characters in a String. Is that unacceptable for the bundle, or shared preferences?Thanks
Mark
That's a lot of data =) But if I had to store it, I'd store it in `SharedPreferences` I think. I'm afraid I haven't read any best practices with regards to how much the bundle should hold, so I can't really comment on that.
David Hedlund
A: 

If you want to preserve an object across simple activity changes, try Activity.onRetainNonConfigurationInstance().

ralfoide
No, that method purely exists for optimization reasons. You must not rely on it being called, and thus, you still have to store away stuff in onSaveInstanceState().
Matthias
A: 

Hmm all good points, thanks. For now I'm storing in an sqlite database, kind of slow, but necessary.

mark