android - No performance improvement by using AsyncTask inside instantiateItem (PagerAdapter) -


i using viewpager display images full screen. click image thumbnail , new activity starts has image full screen. images displayed creating bitmaps file path of system. since bitmap processing resource intensive have moved inside asynctask thread. however, despite doing see no improvement in performance.

my activity transition still delayed , not see progress dialog.

public class zoomimageadapter extends pageradapter {  private context mcontext; private list<string> imagepathdata = new arraylist<string>(); private layoutinflater layoutinflater; private view itemview; private touchimageview imageview; private viewgroup container;   public zoomimageadapter(context context, list<string> data){     this.mcontext = context;     this.imagepathdata = data; }  @override public int getcount() {     return this.imagepathdata.size(); }  @override public boolean isviewfromobject(view view, object object) {     return view == ((relativelayout) object); }  @override public object instantiateitem(viewgroup container, int position) {     this.container = container;            bitmaphandling bitmaphandling = new bitmaphandling();     bitmaphandling.execute(imagepathdata.get(position));      view result = null;      try {         result = bitmaphandling.get();     } catch (interruptedexception e) {         e.printstacktrace();     } catch (executionexception e) {         e.printstacktrace();     }      return result; }  private class bitmaphandling extends asynctask<string, view, view>{      progressdialog progressdialog;     string path;     bitmap bitmap;      @override     protected void onpreexecute(){         progressdialog = progressdialog.show(mcontext,"","");         layoutinflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service);         itemview = layoutinflater.inflate(r.layout.item_zoomimage, container, false);     }      @override     protected view doinbackground(string... params) {          path = params[0];         bitmap = utility.compressbitmap(bitmapfactory.decodefile(path), 720);          return itemview;     }      @override     protected void onpostexecute(view result){         progressdialog.dismiss();          imageview = (touchimageview) result.findviewbyid(r.id.iv_zoomimage);         imageview.setimagebitmap(bitmap);         ((viewpager) container).addview(result, 0);     } }  @override public void destroyitem(viewgroup container, int position, object object) {     ((viewpager) container).removeview((relativelayout) object); } } 

your code wouldn't compile, @ doinbackground() method.:)

anyway - not work because call asynctask.get() blocking. waits background task complete , return result.

you have rather return (probably custom view) instantiateitem() method right away , start bitmaphandling task within there.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -