gson - OutOfMemoryError when try to store big data in SharedPreferences, Android -


problem: want store huge map of objects (1000 contacts) sharedpreferences.

i have cordova application 1st time load contacts , convert photos base64 string.

generally process might take 30 sec. reason goal store contacts string sharedpreferences load after quickly.

i use gson library no matter do, get:

java.lang.outofmemoryerror        @ java.lang.string.<init>(string.java:354)        @ java.lang.string.<init>(string.java:171)        @ java.io.bytearrayoutputstream.tostring(bytearrayoutputstream.java:137) 

this method convert map bytearrayoutputstream exception in last line: out.tostring()


public static string getstrfromgroupslistjsonobject(concurrenthashmap<string, wmcontactimage> contactmap){          gson gson = getinstance();           outputstream out = new bytearrayoutputstream();          try {             jsonwriter writer = new jsonwriter(new outputstreamwriter(out, "utf-8"));              iterator<string> = contactmap.keyset().iterator();              wmcontactimage img;              writer.beginobject(); // {               while(it.hasnext()){                 string key = it.next();                  writer.name(key);                  img = contactmap.get(key);                  gson.tojson(img, wmcontactimage.class, writer);             }                         writer.endobject();   // }             writer.close();                      } catch (unsupportedencodingexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }          return out.tostring();     }  

is there other way store map in sharedpreferences or can somehow store outputstream?

use file http://developer.android.com/guide/topics/data/data-storage.html . shared preferences not supposed store big data. use file or sqlote database.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -