Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.34k stars 10.69k forks source link

ToastUtils崩溃 #1510

Open Dboy233 opened 3 years ago

Dboy233 commented 3 years ago

version:1.30.6

MainActivity 双击退出

image

    @Override
    public void onBackPressed() {
        if (DoublePressedExit.isDoublePressed()) {
            super.onBackPressed();
        } else {
            ToastUtils.showShort("再次点击退出应用");
        }
    }

出现崩溃

image

android.view.WindowLeaked: Activity com.work.demo.main.MainActivity has leaked window android.widget.ImageView{7cdd26b V.ED..... ......ID 0,0-278,83} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:591)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:362)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
        at com.blankj.utilcode.util.ToastUtils$WindowManagerToast.show(ToastUtils.java:630)
        at com.blankj.utilcode.util.ToastUtils$ActivityToast.showWithActivityWindow(ToastUtils.java:739)
        at com.blankj.utilcode.util.ToastUtils$ActivityToast.show(ToastUtils.java:680)
        at com.blankj.utilcode.util.ToastUtils$2.run(ToastUtils.java:494)
        at com.blankj.utilcode.util.ThreadUtils.runOnUiThread(ThreadUtils.java:70)
        at com.blankj.utilcode.util.UtilsBridge.runOnUiThread(UtilsBridge.java:554)
        at com.blankj.utilcode.util.ToastUtils.show(ToastUtils.java:483)
        at com.blankj.utilcode.util.ToastUtils.show(ToastUtils.java:472)
        at com.blankj.utilcode.util.ToastUtils.showShort(ToastUtils.java:383)
        at com.work.demo.main.MainActivity.onBackPressed(MainActivity.java:204)
Dboy233 commented 3 years ago

version:1.30.6

手机型号:OPPO

image

nxnyk commented 3 years ago

+1 同遇到该问题

xiaolong125 commented 2 years ago

+1

iFCoder commented 2 years ago

+1 同遇该问题,楼主解决了吗? @Dboy233

Dboy233 commented 2 years ago

+1 同遇该问题,楼主解决了吗? @Dboy233

库里面似乎是没有解决这个问题。也有可能是手机的问题。总之,这个地方我替换为了Android Api Toast

wangyichn66 commented 2 years ago

+1 同 替换为了Android Api Toast 但是系统的Toast是黑色的 不好看 :(

tribbianiwang commented 2 years ago

+1

Andy045 commented 1 year ago

Activity销毁时调用下 ToastUtils.cancel()方法。 可以在BaseActivity.onDestroy() 或者 lifecycle.addObserver() 中通用处理

Dboy233 commented 1 year ago

Activity销毁时调用下 ToastUtils.cancel()方法。 可以在BaseActivity.onDestroy() 或者 lifecycle.addObserver() 中通用处理

其实问题是我结束activity后,希望这个toast继续保持,因为Toast展示的时候,使用的context是applicationContext,按理说不应该回出问题.

而且我还发现了,如果app没有退出,只退出当前activity的话,控制台回提示当前activity泄漏