当我滚动浏览我的webview应用程序时,应用程序被冻结。

问题描述 投票:0回答:1

该应用由简单的闪屏和webview组成。但是在webview方面,应用程序出现了冻结的问题。当我滚动时,它不能准确地工作。在正常的浏览器中没有冻结。到底是什么问题呢?

闪屏


public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(SplashScreen.this,MainActivity.class));
                finish();
            }

        }, 1200);



    }
}

主要活动

public class MainActivity extends AppCompatActivity {

   private final static int FCR = 1;
   WebView webView;
   private String mCM;
   private ValueCallback<Uri> mUploadMessage;
   public ValueCallback<Uri[]> uploadMessage;
   public static final int REQUEST_SELECT_FILE = 100;
   private final static int FILECHOOSER_RESULTCODE = 1;

   @SuppressLint("WrongViewCast")
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       webView = findViewById(R.id.webView);
       webView.loadUrl("https://dokuzlama.com");
       WebSettings webSettings = webView.getSettings();
       webSettings.setJavaScriptEnabled(true);
       webSettings.setSupportZoom(false);
       webSettings.setAllowFileAccess(true);
       webSettings.setAllowFileAccess(true);
       webSettings.setAllowContentAccess(true);

       webView.setWebViewClient(new Callback());
       webView.setWebChromeClient(new WebChromeClient()
       {
           // For 3.0+ Devices (Start)
           // onActivityResult attached before constructor
           protected void openFileChooser(ValueCallback uploadMsg, String acceptType)
           {
               mUploadMessage = uploadMsg;
               Intent i = new Intent(Intent.ACTION_GET_CONTENT);
               i.addCategory(Intent.CATEGORY_OPENABLE);
               i.setType("image/*");
               startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);
           }


           // For Lollipop 5.0+ Devices
           public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
           {
               if (uploadMessage != null) {
                   uploadMessage.onReceiveValue(null);
                   uploadMessage = null;
               }

               uploadMessage = filePathCallback;

               Intent intent = fileChooserParams.createIntent();
               try
               {
                   startActivityForResult(intent, REQUEST_SELECT_FILE);
               } catch (ActivityNotFoundException e)
               {
                   uploadMessage = null;
                   Toast.makeText(MainActivity.this.getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();
                   //eski---- >   Toast.makeText(getActivity().getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();
                   return false;
               }
               return true;
           }

           //For Android 4.1 only
           protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
           {
               mUploadMessage = uploadMsg;
               Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
               intent.addCategory(Intent.CATEGORY_OPENABLE);
               intent.setType("image/*");
               startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE);
           }

           protected void openFileChooser(ValueCallback<Uri> uploadMsg)
           {
               mUploadMessage = uploadMsg;
               Intent i = new Intent(Intent.ACTION_GET_CONTENT);
               i.addCategory(Intent.CATEGORY_OPENABLE);
               i.setType("image/*");
               startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
           }
       });
   }

   public class Callback extends WebViewClient {
       public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
           Toast.makeText(getApplicationContext(), "Uygulama yüklenemedi", Toast.LENGTH_SHORT).show();
       }
   }

   @Override
   public void onActivityResult(int requestCode, int resultCode, Intent intent) {
       super.onActivityResult(requestCode, resultCode, intent);
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
           if (requestCode == REQUEST_SELECT_FILE) {
               if (uploadMessage == null)
                   return;
               uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
               uploadMessage = null;
           }
       } else if (requestCode == FILECHOOSER_RESULTCODE) {
           if (null == mUploadMessage)
               return;
           // Use MainActivity.RESULT_OK if you're implementing WebView inside Fragment
           // Use RESULT_OK only if you're implementing WebView inside an Activity
           Uri result = intent == null || resultCode != MainActivity.RESULT_OK ? null : intent.getData();
           mUploadMessage.onReceiveValue(result);
           mUploadMessage = null;
       } else
           Toast.makeText(MainActivity.this.getApplicationContext(), "Failed to Upload Image", Toast.LENGTH_LONG).show();
       //eski____ Toast.makeText(getActivity().getApplicationContext(), "Failed to Upload Image", Toast.LENGTH_LONG).show();
   }

   @Override
   public void onBackPressed() {
       if (webView.canGoBack()){
           webView.goBack();
       } else {
           super.onBackPressed();
       }
   }
}

我研究分析了很多,但我找不到。

android webview splash-screen
1个回答
0
投票

试着在你的活动中的manifest中启用硬件加速。

android:hardwareAccelerated="true"
© www.soinside.com 2019 - 2024. All rights reserved.