【发布时间】:2013-11-05 05:12:25
【问题描述】:
与question 类似,但解决方案在 mycase 中不起作用。
运行函数 webview.loadUrl 时 Android 应用程序崩溃
关闭时出现以下错误:
E/AndroidRuntime(1593):由以下原因引起: java.lang.Throwable:警告:在线程上调用了 WebView 方法 'WebViewCoreThread'。必须在 UI 上调用所有 WebView 方法 线。未来版本的 WebView 可能不支持在其他版本上使用 线程。
编辑:现在尝试在 runOnUiThread(new Runnable(){ }) 中运行该函数,但出现错误并且无法在上下文中输入 runOnUiThread 的位置。
这是完整的代码:
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();
}
}
【问题讨论】:
标签: android multithreading url webview crash