From 445ddd89fb3269a772978a9860247065e5886249 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 3 Jul 2014 13:27:30 -0400 Subject: [PATCH] CB-6761 Fix native->JS bridge ceasing to fire when page changes and online is set to false and the JS loads quickly --- .../org/apache/cordova/NativeToJsMessageQueue.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 5d0c061b..9f6f96ef 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -308,23 +308,28 @@ public class NativeToJsMessageQueue { /** Uses online/offline events to tell the JS when to poll for messages. */ private class OnlineEventsBridgeMode extends BridgeMode { private boolean online; - final Runnable runnable = new Runnable() { + private boolean ignoreNextFlush; + + final Runnable toggleNetworkRunnable = new Runnable() { public void run() { if (!queue.isEmpty()) { + ignoreNextFlush = false; webView.setNetworkAvailable(online); } - } + } }; @Override void reset() { online = false; + // If the following call triggers a notifyOfFlush, then ignore it. + ignoreNextFlush = true; webView.setNetworkAvailable(true); } @Override void onNativeToJsMessageAvailable() { - cordova.getActivity().runOnUiThread(runnable); + cordova.getActivity().runOnUiThread(toggleNetworkRunnable); } // Track when online/offline events are fired so that we don't fire excess events. @Override void notifyOfFlush(boolean fromOnlineEvent) { - if (fromOnlineEvent) { + if (fromOnlineEvent && !ignoreNextFlush) { online = !online; } }