Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect image rendered with Glide library

I am using the glide library in my android project to fetch and display images. Earlier I was using version 2.0.5 and facing rendering issue. The problem was that the wrong images were rendering. I have updated library to 3.3 version and it now crashes with the following exception.

14-Sep-2014 08:41:31 PM java.lang.IllegalArgumentException: 
You cannot start a load for a destroyed activity
    at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:63)
    at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:29)
    at com.bumptech.glide.Glide.with(Glide.java:537)
    at com.miamiheat.common.MHImageDownloadWrapper.loadImage(MHImageDownloadWrapper.java:12)
    at com.miamiheat.ui.module.MHWallpaperModule.setWallpaperViewData(MHWallpaperModule.java:234)
    at com.miamiheat.ui.module.MHWallpaperModule.taskManagerResponseCallback(MHWallpaperModule.java:257)
    at com.miamiheat.service.taskmanager.MHWallpaperTaskManager.asyncResultCallback(MHWallpaperTaskManager.java:133)
    at com.miamiheat.service.framework.MHAsyncServiceTask.onPostExecute(MHAsyncServiceTask.java:191)
    at android.os.AsyncTask.finish(AsyncTask.java:631)
    at android.os.AsyncTask.access$600(AsyncTask.java:177)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)

Is there anyway to cancel the image download request on activity destroy.

like image 981
Manish Avatar asked Sep 13 '14 12:09

Manish


2 Answers

Glide.clear() sometimes doesn't help for me. Pass application context to Glide.with(...) using getApplicationContext() method.

like image 51
user2028928 Avatar answered Oct 19 '22 06:10

user2028928


You can always use Glide.clear() to cancel a load.

However, that exception occurs when you try to start a new load after your activity has been destroyed. Are you starting to load images after fetching some data asynchronously? If so you probably want to cancel your async fetch when your activity is stopped or at least ignore the result if the fetch finishes and your activity is destroyed.

like image 27
Sam Judd Avatar answered Oct 19 '22 08:10

Sam Judd