Storing Large Arraylists To Sqlite
I im developing a application in which I continuously download large amount of data. The data in json format and I use Gson to deserialize it. By now Im storing this in a SQLite db
Solution 1:
Yes, serialization is a better solution in your case and it works in Android. The following example is taken from http://www.jondev.net/articles/Android_Serialization_Example_%28Java%29
serialization method:
publicstaticbyte[] serializeObject(Object o) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(o);
out.close();
// Get the bytes of the serialized object byte[] buf = bos.toByteArray();
return buf;
} catch(IOException ioe) {
Log.e("serializeObject", "error", ioe);
returnnull;
}
deserialization method:
publicstaticObjectdeserializeObject(byte[] b) {
try {
ObjectInputStreamin = newObjectInputStream(newByteArrayInputStream(b));
Objectobject = in.readObject();
in.close();
returnobject;
} catch(ClassNotFoundException cnfe) {
Log.e("deserializeObject", "class not found error", cnfe);
returnnull;
} catch(IOException ioe) {
Log.e("deserializeObject", "io error", ioe);
returnnull;
}
Post a Comment for "Storing Large Arraylists To Sqlite"