简体   繁体   English

android 4.4.2中的webview冻结

[英]webview freeze in android 4.4.2

i have an application in that i am loading webview in activity with url also there is drawer and this is freeze in android 4.4.2 , thats working fine in android 5.0 and 6.0 onward 我有一个应用程序,我正在使用url在活动中加载webview,也有抽屉,这在android 4.4.2中冻结,多数民众赞成在Android 5.0和6.0及更高版本中工作正常

as per android monitor log in freeze case is below , thats log is repeat on every swype or touch 根据以下冻结情况下的android监视器日志,多数民众赞成在每次扫描或触摸时重复该日志

  • I/View: Touch down dispatch to android.webkit.WebView{42841ec0 VFED..C. I / View:降落调度到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 } .F ...... 0,0-480,666#7f100075 app:id / web_view},事件= MotionEvent {action = ACTION_DOWN,id [0] = 0,x [0] = 248.48233,y [0] = 327.48773 ,toolType [0] = TOOL_TYPE_FINGER,buttonState = 0,metaState = 0,标志= 0x0,edgeFlags = 0x0,pointerCount = 1,historySize = 0,eventTime = 20907060,downTime = 20907060,deviceId = 3,source = 0x1002}
    • D/VelocityTracker: Couldn't open '/dev/touch' (Permission denied) D / VelocityTracker:无法打开“ / dev / touch”(权限被拒绝)
    • D/VelocityTracker: tpd read x fail: Bad file number D / VelocityTracker:tpd读取x失败:错误的文件编号
    • D/VelocityTracker: tpd read y fail: Bad file number D / VelocityTracker:tpd读y失败:错误的文件号
    • I/View: Touch up dispatch to android.webkit.WebView{42841ec0 VFED..C. I / View:修改调度到android.webkit.WebView {42841ec0 VFED..C。 .F...... 0,0-480,666 #7f100075 app:id/web_view}, event = MotionEvent { action=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, downTime=20907060, deviceId=3, source=0x1002 } .F ...... 0,0-480,666#7f100075 app:id / web_view},事件= MotionEvent {action = ACTION_UP,id [0] = 0,x [0] = 248.48233,y [0] = 327.48773 ,toolType [0] = TOOL_TYPE_FINGER,buttonState = 0,metaState = 0,标志= 0x0,edgeFlags = 0x0,pointerCount = 1,historySize = 0,eventTime = 20907129,downTime = 20907060,deviceId = 3,source = 0x1002}

and i set webview property like 我将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);

and i set webclient 我设置了webclient

webView.setWebChromeClient(new WebChromeClient() {            

@Override public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { return true; @Override public boolean onShowFileChooser(WebView webView,ValueCallback filePathCallback,FileChooserParams fileChooserParams){返回true; } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } @Override public void onGeolocationPermissionsShowPrompt(String origin,GeolocationPermissions.Callback callback){callback.invoke(origin,true,false); } // openFileChooser for Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { } // openFileChooser for Android < 3.0 public void openFileChooser(ValueCallback uploadMsg) { } //openFileChooser for other Android versions public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } // Android 3.0以上版本的openFileChooser公共无效openFileChooser(ValueCallback uploadMsg,字符串acceptType){} // Android下的openFileChooser <3.0公共无效openFileChooser(ValueCallback uploadMsg){} //其他Android版本的openFileChooser公共无效openFileChooser(ValueCallback uploadMsg,字符串acceptType,字符串捕获){openFileChooser(uploadMsg,acceptType); } public boolean onConsoleMessage(ConsoleMessage cm) { onConsoleMessage(cm.message(), cm.lineNumber(), cm.sourceId()); } public boolean onConsoleMessage(ConsoleMessage cm){onConsoleMessage(cm.message(),cm.lineNumber(),cm.sourceId()); return true; 返回true; } public void onConsoleMessage(String message, int lineNumber, String sourceID) { } }); } public void onConsoleMessage(String message,int lineNumber,String sourceID){}}); // End setWebChromeClient //结束setWebChromeClient

    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);
        }
    });

and here is my xml 这是我的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>

Gradle with 3.0.0 and above and compileSdkVersion 26 above cause this problem... 使用3.0.0及更高版本的Gradle以及上面的compileSdkVersion 26会导致此问题...

My solution is not exact solution but it solve the problem... switch app gradle to 我的解决方案不是确切的解决方案,但它解决了问题。

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

switch module gradle to 切换模块gradle到

compileSdkVersion 25
buildToolsVersion '25.0.2'

change all other api to max 25 will solve frezee problem.. Until Main Solution comes it is worth to change these things! 将所有其他api更改为最大25即可解决frezee问题。在“主要解决方案”出现之前,值得更改这些东西!

Seems "Kotlin" is not as expected... Cause More work for CPU 似乎“ Kotlin”与预期不符...原因CPU的更多工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM