Commit 4885cdf8 authored by Darryl Pogue's avatar Darryl Pogue
Browse files

Android: Avoid blocking the main thread.

parent 9044fb23
Loading
Loading
Loading
Loading
+12 −5
Changes for src/android/LocalNotification.java: 12 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -68,15 +68,14 @@ public class LocalNotification extends CordovaPlugin {
    }

    @Override
    public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    public boolean execute (String action, final JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equalsIgnoreCase("add")) {
            cordova.getThreadPool().execute( new Runnable() {
                public void run() {
                    JSONObject arguments  = args.optJSONObject(0);
            final Options options = new Options(context).parse(arguments);
                    Options options = new Options(context).parse(arguments);

                    persist(options.getId(), args);

            cordova.getThreadPool().execute( new Runnable() {
                public void run() {
                    add(options);
                }
            });
@@ -85,17 +84,25 @@ public class LocalNotification extends CordovaPlugin {
        }

        if (action.equalsIgnoreCase("cancel")) {
            cordova.getThreadPool().execute( new Runnable() {
                public void run() {
                    String id = args.optString(0);

                    cancel(id);
                    unpersist(id);
                }
            });

            return true;
        }

        if (action.equalsIgnoreCase("cancelAll")) {
            cordova.getThreadPool().execute( new Runnable() {
                public void run() {
                    cancelAll();
                    unpersistAll();
                }
            });

            return true;
        }