본문 바로가기

Mobile/Android

[ Android ] a webview method was called on thread 'javabridge' 에러가 발생했을 때

안드로이드 Webview에서 Javascript를 호출할 때 하기와 같이 ll WebView methods must be called on the same thread.라는 메시지가 뜰 때 있습니다.

 

 W/WebView: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {b815192} called on Looper (JavaBridge, tid 1239) {8687233}, FYI main Looper is Looper (main, tid 2) {b815192})
        at android.webkit.WebView.checkThread(WebView.java:2476)
        at android.webkit.WebView.loadUrl(WebView.java:938)

안드로이드에서 UI 스레드가 사용되어야 하지만 비 UI 스레드에서 호출되기 때문에 발생하는 오류입니다.

Javascript 메소드를 비 UI 스레드에서 호출되는 부분을 하기와 같이 호출해 줘야 합니다.

mWebview.post(new Runnable() {
	@Override
	public void run() {
		// TO DO Javascript 메소드 호출
		// ex) mWebview.load();
	}
});