【发布时间】:2017-08-21 08:10:48
【问题描述】:
我正在为 android 开发一个应用程序,其中一些内容通过 WebView 显示。
我有一个这样的 Javascript 接口。
WebAppInterface(Context c, Response response) {
activity = (Activity) c;
delegate = response;
context = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void getResponse(final String operation, final String response, final String type) {
final Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
delegate.didGetResponse(operation, response, type);
Log.d("Success: ", "Im still here"); <-- why am I not back in main thread?
}
});
}
public interface Response {
public void didGetResponse(String operation, String response, String type);
}
我的活动实现了 didGetResponse 并有一个开关,它执行代码并在需要时更新 webview,但仅在 webview 中的第一个函数上,因此在页面设置后 webview 不再响应“点击”
我在想是因为线程还在 javascriptinterface 中?
但是,原生按钮仍然可以更新 web 视图。但是我希望能够从webview中新加载的url调用js函数
【问题讨论】:
-
好的,当我单击新加载的 url 中的元素时,我将其缩小为“未捕获的错误:找不到方法”
标签: javascript android multithreading webview