Domanda

i'm developing an Android app as a client of a cloud webservice. In the login screen, i download a lot of data as JSONs, like a contact list and a list of folders (only name and some feature, not the files included). After a deserialization of this JSONs, i'm storing the list of contacts and the list of folder in two static public list element on the .application file, but in some phones (like galaxy S3 and Galaxy Note 2) when the application goes in background, they saves activities but not this list of data, so if the user come back from background after sometimes he found the app's contactlist empty or with a null pointer exception, because some phose erase this lists. Why? is that possible to save them in other ways? the data is complex, because a contact list object is complex and create a daabase is a lot of work. Another option can be the shared preferences, to store the serialized json of the contactlist, but it can be up to 2MB json.

È stato utile?

Soluzione

Here's the documentation for data storage.

Data Storage

Internal Storage will be the easiest solution. And would fit to requirements.

Altri suggerimenti

this can be a good solution for you : http://www.couchbase.com/communities/couchbase-lite

I think that static variables are almost the first thing that are being garbage collected for memory purposes, so that's why you loose this data. In your onResume method check if your list is null, if it is start the download task again.

If you store your data which comes from cloud to database, then you must use transaction which will safely store all data first, then do other tasks. Please, visit the following links to watch:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction%28%29

I normally use a very nice content-provider approach based on a small little project called Data Droid (http://www.datadroidlib.com/). The patter is very nice and reusable!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top