mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Merge pull request #435 from richturner/master
CB-13975: (android) Fix to fire pause event when cdvStartInBackground=true
This commit is contained in:
commit
b8530a6b70
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user