1

Hello i am having this problem

java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity

I have tried the method other I did during this error but none of them are working. In my case, when my app starts, in its main activity a video is being loaded. When i press back button during that video is being load, my app crashes. Can somebody please help me?

This is my on destroy method

@Override
protected void onDestroy() {

        Glide.with(getApplicationContext()).pauseRequests();
        super.onDestroy();
}

Log:

10-10 12:33:09.294 752-824/? E/WifiConfigStore: updateConfiguration freq=2437 BSSID=c8:50:e9:0f:10:fa RSSI=-44 "nirc1"WPA_PSK
10-10 12:33:09.628 15936-15936/? E/UncaughtException: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
    at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:134)
    at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:102)
    at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:87)
    at com.bumptech.glide.Glide.with(Glide.java:657)
    at com.freesoulapps.preview.android.Preview$7$3.run(Preview.java:277)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
10-10 12:33:09.690 1803-15644/? E/NetworkScheduler: Invalid component specified.
10-10 12:33:10.087 15936-15936/? E/AndroidRuntime: FATAL EXCEPTION: main
Sudeep
  • 67
  • 2
  • 8

3 Answers3

2

Solution:

You must use your_activity_name.this instead of getApplicationContext() and isDestroyed() as shown below:

@override
protected void onDestroy() {
super.onDestroy();

    if (!this.isDestroyed()) {
         Glide.with(your_activity_name.this).pauseRequests();
    }

}

Try it. Hope it helps.

Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41
1

Validate first for check weather your current class context is available or not before do on onDestroy() method.

@override
protected void onDestroy() {
super.onDestroy();

    if (!this.isFinishing ()) {
         Glide.with(getApplicationContext()).pauseRequests();
     }
    }

For more have look this

Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
0

if you use getApplicationContext() while initializing the glide as Glide.with(getApplicationContext()) and pause all request by overriding onDestroy() as

@override
protected void onDestroy() {
super.onDestroy();
Glide.with(getApplicationContext()).pauseRequests();
}
Chetan Ansel
  • 398
  • 2
  • 20