首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法为已销毁的活动启动加载

无法为已销毁的活动启动加载
EN

Stack Overflow用户
提问于 2018-10-10 14:41:06
回答 3查看 3.2K关注 0票数 1

你好,我有这个问题。

代码语言:javascript
复制
java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity

我已经尝试了在此错误期间使用的其他方法,但它们都不起作用。在我的例子中,当我的应用程序启动时,它的主要活动是加载一个视频。当我在加载视频的过程中按下后退按钮时,我的应用程序崩溃了。有人能帮帮我吗?

这是我的on destroy方法

代码语言:javascript
复制
@Override
protected void onDestroy() {

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

日志:

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

发布于 2018-10-10 15:06:47

解决方案:

您必须使用your_activity_name.this而不是getApplicationContext()isDestroyed(),如下所示:

代码语言:javascript
复制
@override
protected void onDestroy() {
super.onDestroy();

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

}

试试看。希望能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2018-10-10 14:44:21

如果在将glide初始化为Glide.with( getApplicationContext() )时使用getApplicationContext(),并通过将onDestroy()重写为

代码语言:javascript
复制
@override
protected void onDestroy() {
super.onDestroy();
Glide.with(getApplicationContext()).pauseRequests();
}
票数 0
EN

Stack Overflow用户

发布于 2018-10-10 14:50:46

在对onDestroy()方法执行操作之前,首先验证以检查当前类上下文是否可用。

代码语言:javascript
复制
@override
protected void onDestroy() {
super.onDestroy();

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

有关更多信息,请查看this

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52734113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档