bitmap - Android: Glide onStart/onResume bug -


i have weird bug glide , i'm not sure it. have function, loads images reddit.com/r/earthporn/

newsdata.data.children[position].data.url list of urls

public void displayimage(final int position) {         drawable d = view.getcontext().getresources().getdrawable(r.drawable.ic_collections_white_24dp);         system.out.println(newsdata.data.children[position].data.url);         glide.with(view.getcontext())                 .load(newsdata.data.children[position].data.url)                 .asbitmap()                     .listener(new requestlistener<string, bitmap>() {                     @override                     public boolean onexception(exception e, string model, target<bitmap> target, boolean isfirstresource) {                         displayimage(position + 1);                          //todo: make sure don't run index out of bounds.                         return false;                     }                      @override                     public boolean onresourceready(bitmap resource, string model, target<bitmap> target, boolean isfrommemorycache, boolean isfirstresource) {                         return false;                     }                 })                 .centercrop()                 .error(d)                 .into(new bitmapimageviewtarget(view.getimageview()) {                     @override                     protected void setresource(bitmap resource) {                         super.setresource(resource);                         view.setimagebitmap(resource);                         wallpaperbitmap = resource;                         system.out.println(resource);                     }                 });     } 

android can't load every single image appears on subreddit. when happens, load next image down. on run today, load image http://imgur.com/hosg2fc, call exception, , load http://i.imgur.com/balufh7.jpg

oncreate, code run expected. runs, hits exception, calls displayimages() again , sets correct image. (please, let me know if there's better way this)

onresume/onstart problem lies. code run, hit exception, place error drawable, call displayimages again not change imageview. setresource(bitmap resource) give me correct bitmap not let me update imageview @ all.

basically, freezes imageview error drawable, or blank white screen if there no drawable , won't let me change it.

calling onresume following code:

 if(wallpaperbitmap != null) {             view.setimageviewpicture(wallpaperbitmap);             //view.showbuttons();             system.out.println("bitmap != null");         }         else {             retrieveimage(subreddit.earth);             system.out.println("bitmap = null");         } 

will set correct picture.

i thought maybe might problem cache tried using diskcachestrategy.none didn't either. last resort, refresh screen once setresource called updated bitmap or use picasso i'd rather avoid that.

any appreciated!

edit: i'm getting error: d/skia﹕ --- skimagedecoder::factory returned null onstart

glide may restart failed requests in onstart, trigger failure, set error drawable. fix this, should 2 things:

  1. always call clear() on views , targets before calling setimageresource/setimagedrawable (outside of onresourceready). calling clear() prevent glide managing view/target, in turn stop glide restarting loading in onstart.

  2. if ever keep reference resource loaded glide (usually bitmap or drawable, need make sure null out reference when target's onloadcleared or onloadfailed methods called. isn't directly related issue, it's error in code above , can lead weird errors if glide re-uses bitmap while you're referencing it.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -