你好,我有这个问题。
java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity我已经尝试了在此错误期间使用的其他方法,但它们都不起作用。在我的例子中,当我的应用程序启动时,它的主要活动是加载一个视频。当我在加载视频的过程中按下后退按钮时,我的应用程序崩溃了。有人能帮帮我吗?
这是我的on destroy方法
@Override
protected void onDestroy() {
Glide.with(getApplicationContext()).pauseRequests();
super.onDestroy();
}日志:
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发布于 2018-10-10 15:06:47
解决方案:
您必须使用your_activity_name.this而不是getApplicationContext()和isDestroyed(),如下所示:
@override
protected void onDestroy() {
super.onDestroy();
if (!this.isDestroyed()) {
Glide.with(your_activity_name.this).pauseRequests();
}
}试试看。希望能有所帮助。
发布于 2018-10-10 14:44:21
如果在将glide初始化为Glide.with( getApplicationContext() )时使用getApplicationContext(),并通过将onDestroy()重写为
@override
protected void onDestroy() {
super.onDestroy();
Glide.with(getApplicationContext()).pauseRequests();
}发布于 2018-10-10 14:50:46
在对onDestroy()方法执行操作之前,首先验证以检查当前类上下文是否可用。
@override
protected void onDestroy() {
super.onDestroy();
if (!this.isFinishing ()) {
Glide.with(getApplicationContext()).pauseRequests();
}
}有关更多信息,请查看this
https://stackoverflow.com/questions/52734113
复制相似问题