本文介绍了Android应用程序崩溃的网页流量变化的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此类似question,但溶液没有在mycase工作

运行功能webview.loadUrl Android应用程序崩溃/>
获取有关关闭了以下错误:

EDIT: Trying now to run the function in runOnUiThread(new Runnable(){ }) but getting errors and having trouble with where to enter runOnUiThread within context.
Here is full code:

   public class MyJavaScriptInterface {  
         @JavascriptInterface 
             public void androidFieldPrompt(String title, String msg, final String funct) {  
                 final EditText input = new EditText(MainActivity.this);  
                 AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);                 
                 alert.setTitle(title);  
                 alert.setMessage(msg);  
                 alert.setView(input);
                 alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {    
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        String value = input.getText().toString();  

                        // ERROR IS BEING THROWN HERE
                        webView.loadUrl("javascript:window."+funct+"('"+value+"')"); 

                        return;                  
                       }  
                    });  
                alert.show();        
             }
   }
解决方案

As the error points out .. you are calling webview methods on non UI Thread (inside a click listener ).

you should use runOnUiThread to use main thread when calling web view method , inside onClick

  MainActivity.this.runOnUiThread(new Runnable(){
       @Override
        public void run() {
           String value = input.getText().toString();
           webView.loadUrl("javascript:window."+funct+"('"+value+"')");
           return;
        }
 });

这篇关于Android应用程序崩溃的网页流量变化的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 04:27