Commit 7a0c648d authored by Simon MacDonald's avatar Simon MacDonald
Browse files

Issue #169: PushNotification.init blocked the main thread for Android

parent aa4b7a18
Loading
Loading
Loading
Loading
+12 −12
Changes for src/android/com/adobe/phonegap/push/PushPlugin.java: 12 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -37,13 +37,13 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {
    }

    @Override
    public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

        boolean result = false;

    public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) {
        Log.v(LOG_TAG, "execute: action=" + action);
        gWebView = this.webView;

        if (INITIALIZE.equals(action)) {
            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    pushContext = callbackContext;
                    JSONObject jo = null;

@@ -52,7 +52,6 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {
                    try {
                        jo = data.getJSONObject(0).getJSONObject(ANDROID);

                gWebView = this.webView;
                        Log.v(LOG_TAG, "execute: jo=" + jo.toString());

                        String senderID = jo.getString(SENDER_ID);
@@ -60,10 +59,8 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {
                        Log.v(LOG_TAG, "execute: senderID=" + senderID);

                        GCMRegistrar.register(getApplicationContext(), senderID);
                result = true;
                    } catch (JSONException e) {
                        Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
                result = false;
                        callbackContext.error(e.getMessage());
                    }

@@ -91,21 +88,24 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {
                        sendExtras(gCachedExtras);
                        gCachedExtras = null;
                    }

                }
            });
        } else if (UNREGISTER.equals(action)) {

            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    GCMRegistrar.unregister(getApplicationContext());

                    Log.v(LOG_TAG, "UNREGISTER");
            result = true;
                    callbackContext.success();
                }
            });
        } else {
            result = false;
            Log.e(LOG_TAG, "Invalid action : " + action);
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
            return false;
        }

        return result;
        return true;
    }

    public static void sendEvent(JSONObject _json) {