Fix main thread bug

This commit is contained in:
Sebastián Katzer 2014-12-14 13:23:10 +01:00
parent 9d3cce0d18
commit 0994147d13

View File

@ -42,6 +42,9 @@ public class BackgroundMode extends CordovaPlugin {
ACTIVATE, DEACTIVATE, FAILURE ACTIVATE, DEACTIVATE, FAILURE
} }
// Plugin namespace
private static final String JS_NAMESPACE = "cordova.plugins.backgroundMode";
// Flag indicates if the app is in background or foreground // Flag indicates if the app is in background or foreground
private boolean inBackground = false; private boolean inBackground = false;
@ -247,10 +250,14 @@ public class BackgroundMode extends CordovaPlugin {
} }
String js = String.format("setTimeout('cordova.plugins.backgroundMode" + final String js = String.format("setTimeout('%s.on%s(%s)',0)",
".on%s(%s)',0)", JS_NAMESPACE, eventName, params);
eventName, params);
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
webView.loadUrl("javascript:" + js); webView.loadUrl("javascript:" + js);
} }
});
}
} }