public class HydraPlugin extends CordovaPlugin { @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { switch (action) { case "navigateBack": return handleNavigateBack(args, callbackContext); default: callbackContext.error("Unknown action: " + action); return false; } } private boolean handleNavigateBack(JSONArray args, CallbackContext callbackContext) throws JSONException { int delta = args.optInt(0, 1); // 获取当前视图 Activity currentActivity = cordova.getActivity(); boolean success = hydraActivity.navigateBack(delta); if (success) { callbackContext.success(); } else { callbackContext.error("Cannot navigate back: no history or reached limit"); } return true; }}
遇到的错误:
java.lang.RuntimeException: 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) {7e298f7} called on Looper (JavaBridge, tid 190) {9f6eea2}, FYI main Looper is Looper (main, tid 2) {7e298f7}) at android.webkit.WebView.checkThread(WebView.java:2627) at android.webkit.WebView.canGoBack(WebView.java:947)