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.32k stars 10.69k forks source link

使用ToastUtils时导致App闪退 #1785

Closed zhwanng closed 1 year ago

zhwanng commented 1 year ago

描述 Bug

使用ToastUtils时导致App闪退

Tried to obtain display from a Context not associated with one. Only visual Contexts (such as Activity or one created with Context#createWindowContext) or ones created with Context#createDisplayContext are associated with displays. Other types of Contexts are typically related to background entities and may return an arbitrary display.

相关代码

    private void parseAppVersion(AppVersionInfoModel model) {
        String curVer = AppUtils.getAppVersionName();
        boolean needToUpgrade = AppVersions.compare(curVer, model.version);
        if (!needToUpgrade) {
            ToastUtils.showLong(R.string.tip_app_version_already_latest);
            return;
        }
    }

异常堆栈

 java.lang.UnsupportedOperationException: Tried to obtain display from a Context not associated with one. Only visual Contexts (such as Activity or one created with Context#createWindowContext) or ones created with Context#createDisplayContext are associated with displays. Other types of Contexts are typically related to background entities and may return an arbitrary display.
  at android.app.ContextImpl.getDisplay(ContextImpl.java:3041)
  at android.content.ContextWrapper.getDisplay(ContextWrapper.java:1161)
  at com.android.tools.agent.appinspection.proto.ViewExtensionsKt.getDefaultDisplayRotation(ViewExtensions.kt:181)
  at com.android.tools.agent.appinspection.proto.ViewExtensionsKt.createAppContext(ViewExtensions.kt:157)
  at com.android.tools.agent.appinspection.CaptureExecutor.sendLayoutEvent(CaptureExecutor.kt:173)
  at com.android.tools.agent.appinspection.CaptureExecutor.executeCapture(CaptureExecutor.kt:145)
  at com.android.tools.agent.appinspection.CaptureExecutor.access$executeCapture(CaptureExecutor.kt:42)
  at com.android.tools.agent.appinspection.CaptureExecutor$execute$1.run(CaptureExecutor.kt:75)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
  at java.lang.Thread.run(Thread.java:1012)

截图

zhwanng commented 1 year ago

不知道咋回事,它自己又能用了🧐

VamPeng commented 7 months ago

我也遇到了。单纯的一个rv列表里oncreatview添加了一个点击以后toast的事件