Repository: cordova-plugin-dialogs Updated Branches: refs/heads/master 4ebf797ab -> 1374373f2
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/1374373f Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/1374373f Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/1374373f Branch: refs/heads/master Commit: 1374373f293338b551afe58ff27244404f7232f8 Parents: 4ebf797 Author: Archana Naik <[email protected]> Authored: Wed Apr 9 22:42:33 2014 -0700 Committer: Archana Naik <[email protected]> Committed: Mon Apr 28 15:12:18 2014 -0700 ---------------------------------------------------------------------- src/android/Notification.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/1374373f/src/android/Notification.java ---------------------------------------------------------------------- diff --git a/src/android/Notification.java b/src/android/Notification.java index 558507e..3738545 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() { @@ -252,7 +258,7 @@ public class Notification extends CordovaPlugin { * @param callbackContext The callback context. */ public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) { - + final CordovaInterface cordova = this.cordova; final EditText promptInput = new EditText(cordova.getActivity()); promptInput.setHint(defaultText);
