Android应用程序崩溃的网页流量变化的网址 [英] android app crashing on webview url change

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

问题描述

与此类似<一个href=\"http://stackoverflow.com/questions/17944347/webview-methods-is-not-called-in-android\">question,但溶液没有在mycase工作

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


  

E / AndroidRuntime(1593):因:
  java.lang.Throwable中:警告:的WebView方法被调用线程上
  WebViewCoreThread。所有的WebView方法必须呼吁UI
  线。的WebView的未来版本可能不支持在其他用途
  线程。


编辑:现在试图运行在runOnUiThread功能(新的Runnable(){}),但得到的错误和具有在哪里范围内进入runOnUiThread麻烦。

这里到处是code:

 公共类MyJavaScriptInterface {
         @JavascriptInterface
             公共无效androidFieldPrompt(字符串名称,弦乐味精,最后弦乐FUNCT){
                 最终的EditText输入=新的EditText(MainActivity.this);
                 AlertDialog.Builder警报=新AlertDialog.Builder(MainActivity.this);
                 alert.setTitle(职称);
                 alert.setMessage(MSG);
                 alert.setView(输入);
                 alert.setPositiveButton(OK,新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释whichButton){
                        字符串值= input.getText()的toString()。                        //错误被抛出HERE
                        webView.loadUrl(JavaScript的:窗口+ FUNCT +('+价值+'));                        返回;
                       }
                    });
                alert.show();
             }
   }


解决方案

  

E / AndroidRuntime(1593):java.lang.Throwable中:产生的原因警告:
  的WebView方法被调用的线程的WebViewCoreThread。所有的WebView
  方法必须在UI线程调用。的WebView的未来版本
  可能不支持其他线程上使用。


由于错误指出..你正在呼吁非UI线程的WebView方法(点击监听器里)。

你应该使用<一个href=\"http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29\">runOnUiThread调用Web视图的方法时要使用主线程,里面的onClick

  MainActivity.this.runOnUiThread(新的Runnable(){
       @覆盖
        公共无效的run(){
           字符串值= input.getText()的toString()。
           webView.loadUrl(JavaScript的:窗口+ FUNCT +('+价值+'));
           返回;
        }
 });

Similar to this question, but solutions are not working in mycase.

Android app is crashing when running function webview.loadUrl
Getting the following error on close:

E/AndroidRuntime(1593): Caused by: java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.

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

解决方案

E/AndroidRuntime(1593): Caused by: java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.

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应用程序崩溃的网页流量变化的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆