[ https://issues.apache.org/jira/browse/CB-13975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16416218#comment-16416218 ]
ASF GitHub Bot commented on CB-13975: ------------------------------------- infil00p closed pull request #435: CB-13975: (android) Fix to fire pause event when cdvStartInBackground=true URL: https://github.com/apache/cordova-android/pull/435 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index e384f8d74..46a23edf2 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -43,6 +43,7 @@ Licensed to the Apache Software Foundation (ASF) under one private BroadcastReceiver telephonyReceiver; private CallbackContext messageChannel; private PluginResult pendingResume; + private PluginResult pendingPause; private final Object messageChannelLock = new Object(); /** @@ -113,6 +114,10 @@ else if (action.equals("exitApp")) { 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 @@ private void sendEventMessage(String action) { } 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) { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Android MainActivity cdvStartInBackground=true fails to fire pause event > ------------------------------------------------------------------------ > > Key: CB-13975 > URL: https://issues.apache.org/jira/browse/CB-13975 > Project: Apache Cordova > Issue Type: Bug > Components: cordova-android > Reporter: Rich T > Assignee: Joe Bowser > Priority: Major > Attachments: CoreAndroid.java > > > The MainActivity created from the template that adds support for starting the > app in the background via the cdvStartInBackground flag doesn't fire the > pause event. Debugging the Android code it looks like onPause is called > before the messageChannel is set so the send event is dropped. > There should probably be a pendingPause flag like the pendingResume. > The reason this is a problem is that I am using the phonegap-push-plugin to > wake the app in the background and I want to know that the app is in the > background so I can disable polling requests which are a data and battery > drain, currently I cannot do this and the app can just be sitting there in > the background consuming resources it doesn't need. -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org