I got an error when js invoke Android's native method on android 5,6,7
Error: Java exception was raised during method invocation
From javascript I am calling native android's method like this:
Android.setIsGoBack(true);
and on android side I have this method in abstract class like:
@JavascriptInterface
override fun setIsGoBack(isGoBack: Boolean) {
(activity as DashBoardActivity).isGoBack = isGoBack
(activity as DashBoardActivity).setHeader("")
}
and I am not sure what is actually getting wrong on Android 5,6,7.
I have fixed the above issue. The problem was I was calling the method from javascript and updating UI (activity as DashBoardActivity).setHeader("") in some other thread than UI. So changed my method to:
@JavascriptInterface
override fun setIsGoBack(isGoBack: Boolean) {
activity?.runOnUiThread {
(activity as DashBoardActivity).isGoBack = isGoBack
(activity as DashBoardActivity).setHeader("")
}
}
updating UI on main thread worked for me.