out of memory error dealing with large bitmaps and the android activity life cycle -


i have scrollable map app has huge bitmap. loads fine on startup, when looses foreground status , user brings backs again im getting out of memory error. in onpause trashes bitmap using recycle, , marks null. onresume checks see if map==null , load bitmap again, crashing program despite me recycling bitmap...here bits of code. of other references bitmap map first check if null before loading/drawing.

onpause

protected void onpause() { super.onpause(); log.e("sys","onpause called"); if (map != null) {         map.recycle();         map = null;         system.gc();         log.e("sys","trashed map"); } } 

my onresume

protected void onresume(){ super.onresume(); log.e("sys","onresume called");  if (map == null)         map = bitmapfactory.decoderesource(getresources(),                         r.drawable.lowresbusmap); log.e("sys","redrew map"); } 

try way:

protected void onresume(){     super.onresume();     if (map == null){         bitmapfactory.options options = new bitmapfactory.options();         options.intempstorage = new byte[16*1024];          map = bitmapfactory.decoderesource(getresources(),                         r.drawable.lowresbusmap, options);     } } 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -