标签:android java 使用 os io 问题 cti div
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); final WebView webView = (WebView)findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new WebChromeClient()); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); javascr = new AndroidJavascript(this, webView); webView.addJavascriptInterface(javascr, "AndroidFunction"); webView.loadUrl("file:///android_asset/www/index.html"); }AndroidJavascript.java
public class AndroidJavascript { Context cont; WebView webView; AndroidJavascript(Context c, WebView w) { cont = c; webView = w; } // function called in the javascript by AndroidFunction.test(); public void test() { webView.loadUrl("javascript:helloBack()"); } }
public void test() { webView.post(new Runnable() { public void run() { webView.loadUrl("javascript:helloBack()"); } }); }这可以将任务放到主UI线程中去执行。
[Android]WebView method must on same thread,布布扣,bubuko.com
[Android]WebView method must on same thread
标签:android java 使用 os io 问题 cti div
原文地址:http://blog.csdn.net/wzy_1988/article/details/38497585