android webview网址切换,Android应用程序崩溃webview网址更改

与此

question类似,但解决方案不适用于我的情况.

运行功能webview.loadUrl时,Android应用程序崩溃

关闭时收到以下错误:

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.

编辑:现在尝试在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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值