【问题标题】:webview freeze in android 4.4.2android 4.4.2 中的 webview 冻结
【发布时间】:2017-12-04 12:09:41
【问题描述】:

我有一个应用程序,我正在使用 url 在活动中加载 webview 还有抽屉 这是在 android 4.4.2 中冻结 ,这在 android 5.0 和 6.0 及以后的版本中运行良好

根据冻结情况下的 android 监视器日志如下 ,每次滑动或触摸都会重复该日志

  • I/View: Touch down dispatch to android.webkit.WebView{42841ec0 VFED..C. .F...... 0,0-480,666 #7f100075 app:id/web_view}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=248.48233, y[0]=327.48773, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20907060,downTime=20907060,deviceId=3,source=0x1002 }
    • D/VelocityTracker:无法打开“/dev/touch”(权限被拒绝)
    • D/VelocityTracker:tpd 读取 x 失败:文件编号错误
    • D/VelocityTracker:tpd 读取失败:文件编号错误
    • I/View:修改调度到 android.webkit.WebView{42841ec0 VFED..C. .F...... 0,0-480,666 #7f100075 app:id/web_view}, event = MotionEvent { 动作=ACTION_UP,id[0]=0,x[0]=248.48233,y[0]=327.48773, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0,pointerCount=1,historySize=0,eventTime=20907129, 停机时间=20907060,设备ID=3,源=0x1002 }

我设置 webview 属性,如

webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.getSettings().setRenderPriority(RenderPriority.HIGH);
    webView.getSettings().setGeolocationEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);

我设置了 webclient

webView.setWebChromeClient(new WebChromeClient() {            

@覆盖 public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { 返回真; } @覆盖 public void onGeolocationPermissionsShowPrompt(字符串来源,GeolocationPermissions.Callback 回调) { callback.invoke(origin, true, false); } // 适用于 Android 3.0+ 的 openFileChooser 公共无效openFileChooser(ValueCallback uploadMsg,字符串acceptType){ } // openFileChooser for Android

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }
        @Override

        public void onPageFinished(WebView view, final String url) {

            super.onPageFinished(view, url);
            CookieSyncManager.getInstance().sync();
            Log.i("finished", url);
        }
    });

这是我的 xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    tools:context=".LandingActivity">

    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/include"
        android:scrollbarStyle="insideOverlay"
        android:scrollbars="none"
        android:visibility="gone" />
    <ImageView
        android:id="@+id/splash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/splash"
        android:visibility="gone" />
    <include
        android:id="@+id/include"
        layout="@layout/bottom_option"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
    <FrameLayout
        android:id="@+id/framLay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">
    </FrameLayout>
</RelativeLayout>
<LinearLayout
    android:layout_width="300dp"
    android:layout_height="fill_parent"
    android:layout_gravity="end"
    android:background="@color/white"
    android:orientation="vertical">
    <ListView
        android:id="@+id/navdrawer"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:drawSelectorOnTop="false"></ListView>
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:background="#454545" />
    <ListView
        android:id="@+id/navdrawer2"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_weight="1"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:drawSelectorOnTop="false"></ListView>
    <TextView
        android:id="@+id/tvVersion"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="1dp"
        android:gravity="center" />
    <include layout="@layout/listview_bottom" />
</LinearLayout>

【问题讨论】:

  • 即使刷新 webview 后仍然无法工作,需要帮​​助
  • 你有什么解决办法吗?
  • 还没有,我的开发还有这个问题
  • 我用的是Xwalk,切换到android webview出现了这个问题

标签: android html android-webview


【解决方案1】:

Gradle 3.0.0 及以上版本和compileSdkVersion 26 以上会导致这个问题...

我的解决方案不是精确的解决方案,但它解决了问题...... 将应用 gradle 切换到

classpath 'com.android.tools.build:gradle:2.3.0'

将模块 gradle 切换到

compileSdkVersion 25
buildToolsVersion '25.0.2'

将所有其他 api 更改为最大 25 将解决冻结问题。在主解决方案出现之前,值得更改这些东西!

似乎“Kotlin”不像预期的那样......导致 CPU 需要更多工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-09
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多