android - How to make an AsyncTask to load Images into Gallery? -


i'm desperate issue in first android app (which published) because there section load imagegallery (the android tweak) 5 images, images files customized ldpi, hdpi , different sizes, problem app crashing in devices (specially on samsung galaxy s3, s4 , s5) don't know do, got error "out of memory" or in samsung galaxy s5, activity opened when tried scroll gallery moment of crash.

the question how can make asynctask load images gallery , preventing outofmemory?

the layout:

 <gallery             android:id="@+id/instalaciones_gallery"             android:layout_width="match_parent"             android:layout_height="fill_parent"              android:layout_below="@+id/arriba_fondo_instalaciones"             /> 

the class:

public class instalacionesactivity extends activity {       integer[] imageids = {              r.drawable.ins1,              r.drawable.ins2,              r.drawable.ins3,              r.drawable.ins4,              r.drawable.ins5              };      context context;     int yolo;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.instalaciones_activity);         context = this;         gallery gallery = (gallery) findviewbyid(r.id.instalaciones_gallery);         gallery.setadapter(new imageadapter(this));       }      public class imageadapter extends baseadapter {         private context context;          public imageadapter(context c)         {         context = c;         }           public int getcount() {         return imageids.length;         }          public object getitem(int position) {         return position;         }          public long getitemid(int position) {         return position;         }          @override         public view getview(int position, view convertview, viewgroup parent) {         imageview imageview = new imageview(context);         imageview.setimageresource(imageids[position]);         imageview.setlayoutparams(new gallery.layoutparams(layoutparams.fill_parent,layoutparams.fill_parent));         imageview.setscaletype(imageview.scaletype.fit_xy);         return imageview;         }         } } 

i don't think asynctask solve problem primarily, suspect loading images large size may more vm limit.

you may need decode , load scaled down version of images.

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -