Merge pull request #435 from richturner/master

CB-13975: (android) Fix to fire pause event when cdvStartInBackground=true
This commit is contained in:
Joe Bowser 2018-03-27 13:50:26 -07:00 committed by GitHub
commit b8530a6b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,7 @@ public class CoreAndroid extends CordovaPlugin {
private BroadcastReceiver telephonyReceiver;
private CallbackContext messageChannel;
private PluginResult pendingResume;
private PluginResult pendingPause;
private final Object messageChannelLock = new Object();
/**
@ -113,6 +114,10 @@ public class CoreAndroid extends CordovaPlugin {
else if (action.equals("messageChannel")) {
synchronized(messageChannelLock) {
messageChannel = callbackContext;
if (pendingPause != null) {
sendEventMessage(pendingPause);
pendingPause = null;
}
if (pendingResume != null) {
sendEventMessage(pendingResume);
pendingResume = null;
@ -321,7 +326,19 @@ public class CoreAndroid extends CordovaPlugin {
} catch (JSONException e) {
LOG.e(TAG, "Failed to create event message", e);
}
sendEventMessage(new PluginResult(PluginResult.Status.OK, obj));
PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
if (messageChannel == null) {
LOG.i(TAG, "Request to send event before messageChannel initialised: " + action);
if ("pause".equals(action)) {
pendingPause = result;
} else if ("resume".equals(action)) {
// When starting normally onPause then onResume is called
pendingPause = null;
}
} else {
sendEventMessage(result);
}
}
private void sendEventMessage(PluginResult payload) {