07-30 15:07:12.757 26725-26725/com.ganjie.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ganjie.app, PID: 26725
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.Glide.with(Glide.java:653)
at com.ganjie.app.activity.AccountInfoActivity.onSuccess(AccountInfoActivity.java:479)
at com.ganjie.app.network.OkHttpHelper$StringCallBack$5.run(OkHttpHelper.java:208)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6360)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
上面这段报错就是发生在网络请求回调的onsuccess方法中,当用户在网络请求回调时点击了返回键,页面被销毁时,onsuccess中的修改页面的操作往往就会报空指针的错误,因为修改的对象被销毁了,此时还要去修改界面当然会报错。
所以我给出的两个解决办法是
1.在修改页面操作外面加一个判断,判断isfinishing()
2.我认为在极致的情况下判断isfinishing()还是有可能会崩溃的,所以我现在的做法是在外层加一个try ()catch()。
网友评论