Monday, 15 July 2013

java - Out of memory when chaning orientation on activity showing an drawable -



java - Out of memory when chaning orientation on activity showing an drawable -

that's oncreate method:

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_foto); imageview myimageview = (imageview)findviewbyid(r.id.imageview); drawable d = drawable.createfrompath("/mnt/sdcard/pictures/mycameraapp/temp.jpg" ); myimageview.setimagedrawable(d);}

so, i've tried google it, , found lot of informaton on realeasing bitmaps, none realeasing drawables memmory. how realease drawable memmory, , should implement it: onpause or ondestroy?

you getting outofmemoryexception because app using(or needing) more memory granted. happens while loading big bitmaps(images) in memory or showing many bitmaps. have @ developer site showing bitmaps efficiently. utilize next code prevent oom exception:

bitmap scaledbitmap = getresizedbitmap(bitmapfactory.decodefile("/mnt/sdcard/pictures/mycameraapp/temp.jpg"),3,3); public bitmap getresizedbitmap(bitmap bm, int newheight, int newwidth) { int width = bm.getwidth(); int height = bm.getheight(); float scalewidth = ((float) newwidth) / width; float scaleheight = ((float) newheight) / height; // create matrix manipulation matrix matrix = new matrix(); // resize bit map matrix.postscale(scalewidth, scaleheight); // "recreate" new bitmap bitmap resizedbitmap = bitmap.createbitmap(bm, 0, 0, width, height, matrix, false); homecoming resizedbitmap;

}

java android out-of-memory

No comments:

Post a Comment