Android WebView内容故障

Android WebView内容故障,android,android-studio,webview,Android,Android Studio,Webview,我用一个简单的webview打开一个webapp,但是当我在安卓设备上打开它时,它的内容会不时出现问题。我不知道这是否是因为在主线程上做了太多的工作,但这似乎只发生在这个设备上 我的代码是: public class MainActivity extends AppCompatActivity { private WebView webview; private ImageButton forward, back, refresh; @RequiresApi(api

我用一个简单的webview打开一个webapp,但是当我在安卓设备上打开它时,它的内容会不时出现问题。我不知道这是否是因为在主线程上做了太多的工作,但这似乎只发生在这个设备上

我的代码是:


public class MainActivity extends AppCompatActivity {
    private WebView webview;
    private ImageButton forward, back, refresh;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // start lock task mode if it's not already active
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
       // ActivityManager.getLockTaskModeState api is not available in pre-M
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            if (!am.isInLockTaskMode()) {
                startLockTask();
            }
        } else {
            if (am.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_NONE) {
               startLockTask();
            }
        }

        webview = (WebView) findViewById(R.id.webView);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setMediaPlaybackRequiresUserGesture(false);



        //hardware acceleration
        if (Build.VERSION.SDK_INT >= 19) {
            webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        else {
            webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        //cookies
        if(android.os.Build.VERSION.SDK_INT >= 21){
            CookieManager.getInstance().setAcceptThirdPartyCookies(webview, true);
        }else{
            CookieManager.getInstance().setAcceptCookie(true);
        }

      //webSettings.setAppCacheEnabled(false);


        webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {


                if (url.startsWith("intent:")){
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse(url.replaceFirst("intent:", "")));

                    startActivity(intent);

                    return true;
                }
                return false;
            }
        });
        webview.loadUrl("https://partner.ristoro24.it");

I/Choreographer: Skipped 42 frames!  The application may be doing too much work on its main thread.