CB-7261 Fix setNativeToJsBridgeMode sometimes crashing when switching to ONLINE_EVENT
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/41125ea1 Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/41125ea1 Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/41125ea1 Branch: refs/heads/4.0.x Commit: 41125ea1e2ce9bff3191f57d88c10c277cbb3e94 Parents: 73219bf Author: Andrew Grieve <[email protected]> Authored: Thu Aug 7 16:18:56 2014 -0400 Committer: Andrew Grieve <[email protected]> Committed: Thu Aug 7 16:18:56 2014 -0400 ---------------------------------------------------------------------- .../src/org/apache/cordova/NativeToJsMessageQueue.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/41125ea1/framework/src/org/apache/cordova/NativeToJsMessageQueue.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index d05eed8..497366f 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -321,11 +321,16 @@ public class NativeToJsMessageQueue { } } }; + final Runnable resetNetworkRunnable = new Runnable() { + public void run() { + online = false; + // If the following call triggers a notifyOfFlush, then ignore it. + ignoreNextFlush = true; + webView.setNetworkAvailable(true); + } + }; @Override void reset() { - online = false; - // If the following call triggers a notifyOfFlush, then ignore it. - ignoreNextFlush = true; - webView.setNetworkAvailable(true); + cordova.getActivity().runOnUiThread(resetNetworkRunnable); } @Override void onNativeToJsMessageAvailable() { cordova.getActivity().runOnUiThread(toggleNetworkRunnable);
