android - OutOfMemory error, and no idea how to set up bitmaps -


sorry if question bit obvious, i've created app, contains bunch of customized buttons on mainscreen. in beginning, worked fine, made something, no idea what, unfortunately i've forgotten i've done. now, im getting annoying outofmemory error, , i'm not pro in programming, i'm stuck in fixing this. i've tried setting managing bitmap memory, downloaded sample app, got lost in there, didnt found looked mainscreen.

i've tried put code fom developer site in mainscreen.java, think not way works:

//.......old code(not important)........ 

i happy if me, i'm stuck 3 hours on problem.

update

i'm trying scale down images , followed (android dev link) i'm far (following code mainscreen, mainactivity):

    //....................     @override         public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     bitmapfactory.options options = new bitmapfactory.options();             options.injustdecodebounds = true;             bitmapfactory.decoderesource(getresources(), r.id.imageview1, options);             int imageheight = options.outheight;             int imagewidth = options.outwidth;             string imagetype = options.outmimetype;             bitmapfactory.decoderesource(getresources(), r.drawable.hiscr, options);             bitmapfactory.decoderesource(getresources(), r.drawable.sharebutton, options);             bitmapfactory.decoderesource(getresources(), r.drawable.buttongame, options);             bitmapfactory.decoderesource(getresources(), r.drawable.buttongame1, options);             bitmapfactory.decoderesource(getresources(), r.drawable.btn_start, options);             bitmapfactory.decoderesource(getresources(), r.drawable.btn_start2, options);             bitmapfactory.decoderesource(getresources(), r.drawable.btn_start3, options);             bitmapfactory.decoderesource(getresources(), r.drawable.btn_start3locked, options);             bitmapfactory.decoderesource(getresources(), r.drawable.btn_start2locked, options);             }     //.........up there i'm trying decode stuff, contains buttons.xml , images , imageviews.   //..................in code below i'm trying downscaled pictures.       public static int calculateinsamplesize(                 bitmapfactory.options options, int reqwidth, int reqheight) {         // raw height , width of image         final int height = options.outheight;         final int width = options.outwidth;         int insamplesize = 1;          if (height > reqheight || width > reqwidth) {              final int halfheight = height / 2;             final int halfwidth = width / 2;              // calculate largest insamplesize value power of 2 , keeps both             // height , width larger requested height , width.             while ((halfheight / insamplesize) > reqheight                     && (halfwidth / insamplesize) > reqwidth) {                 insamplesize *= 2;             }         }          return insamplesize;     }         //............... 

can use decoderesource everything, listed above customized buttons in xml, pictures.png in drawable folder, , imageviews in layout.xml ?

and after it's not working, i'm still getting outofmemory error.

don't load images @ once if don't need them. also, use bitmap.recycle() remove bitmap , save memory when done bitmap. need every button icon?


Popular posts from this blog