小编ily*_*ets的帖子

Android 10:“由于在 UI 线程被阻止时在错误的线程上调用 WebView API,检测到可能出现死锁”

我的应用程序由带有全屏WebView 的Fragments组成。当用户单击WebView中的链接时,将打开新的Fragment ,其中包含具有相同URL的新WebView。打开新片段之前之前,我关闭软键盘以防万一。我打开新页面的速度非常快。所有操作都在主线程上执行。

根据 Crashlytics 的说法,该问题仅出现在 Android 10 上(所有 Pixel 系列设备和其他具有 10 的设备)。在 Android 10 之前的设备上一切正常。我可以打开很多碎片。但在 Android 10 设备上,这种情况会导致致命异常(随机快速尝试打开新页面 2-3 次后):

E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
Process: <myapp>, PID: 12487
java.lang.RuntimeException: Probable deadlock detected due to WebView API being called on incorrect thread while the UI thread is blocked.
    at Yp.a(PG:13)
    at com.android.webview.chromium.WebViewChromium.onCheckIsTextEditor(PG:4)
    at android.webkit.WebView.onCheckIsTextEditor(WebView.java:3035)
    at android.view.inputmethod.InputMethodManager.checkFocusNoStartInput(InputMethodManager.java:1901)
    at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1863)
    at android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow(InputMethodManager.java:1506)
    at android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow(InputMethodManager.java:1475)
    at <myapp>.Utils.hideKeyboard(Utils.java:175)
    at <myapp>.openNewPage(Pager.java:210) …
Run Code Online (Sandbox Code Playgroud)

android android-webview android-softkeyboard

6
推荐指数
1
解决办法
3693
查看次数

android:fitsSystemWindows在运行时

我的Android应用程序以以下布局开头:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

活动具有状态栏的偏移量.

我想通过单击按钮在运行时删除此偏移量.通过单击按钮我执行以下操作,但它不起作用,没有任何反应:

findViewById(R.id.root).setFitsSystemWindows(false);
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

android

5
推荐指数
2
解决办法
2454
查看次数