You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/04/28 23:28:12 UTC

[28/34] git commit: Added check for isFinishing() on the parent activity to prevent crashes when trying to display dialogs when activity is in this phase of it's lifecycle

Added check for isFinishing() on the parent activity
to prevent crashes when trying to display dialogs when activity
is in this phase of it's lifecycle


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/0beb8dac
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/0beb8dac
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/0beb8dac

Branch: refs/heads/dev
Commit: 0beb8daccab726ca492705221e97bc2d85473db0
Parents: 2b591b2
Author: Archana Naik <na...@lab126.com>
Authored: Wed Apr 9 22:42:33 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Apr 28 11:28:26 2014 -0700

----------------------------------------------------------------------
 src/android/Notification.java | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/0beb8dac/src/android/Notification.java
----------------------------------------------------------------------
diff --git a/src/android/Notification.java b/src/android/Notification.java
index 558507e..d068612 100755
--- a/src/android/Notification.java
+++ b/src/android/Notification.java
@@ -57,6 +57,14 @@ public class Notification extends CordovaPlugin {
      * @return                  True when the action was valid, false otherwise.
      */
     public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
+    	/*
+    	 * Don't run any of these if the current activity is finishing
+    	 * in order to avoid android.view.WindowManager$BadTokenException
+    	 * crashing the app. Just return true here since false should only
+    	 * be returned in the event of an invalid action.
+    	 */
+    	if(this.cordova.getActivity().isFinishing()) return true;
+    	
         if (action.equals("beep")) {
             this.beep(args.getLong(0));
         }
@@ -133,8 +141,7 @@ public class Notification extends CordovaPlugin {
      * @param callbackContext   The callback context
      */
     public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) {
-
-        final CordovaInterface cordova = this.cordova;
+    	final CordovaInterface cordova = this.cordova;
 
         Runnable runnable = new Runnable() {
             public void run() {
@@ -176,8 +183,7 @@ public class Notification extends CordovaPlugin {
      * @param callbackContext   The callback context.
      */
     public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) {
-
-        final CordovaInterface cordova = this.cordova;
+    	final CordovaInterface cordova = this.cordova;
 
         Runnable runnable = new Runnable() {
             public void run() {