This error started occurring when the app is launched for the first time even though I am not sending a push notification:

```
 BroadcastReceiver trying to return result during a non-ordered broadcast
        java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast
                at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:799)
                at android.content.BroadcastReceiver.setResultCode(BroadcastReceiver.java:565)
                at com.pushnotification.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:17)
                at android.app.ActivityThread.handleReceiver(ActivityThread.java:2712)
                at android.app.ActivityThread.access$1700(ActivityThread.java:144)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:155)
                at android.app.ActivityThread.main(ActivityThread.java:5696)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

```

The code for the BroadcastReceiver:

```
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());

        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));

        /* the crash is pointing to this line */
        setResultCode(Activity.RESULT_OK);
    }
}

```

The error started showing up after I implemented the following code in an IntentService (also doesn't get called on app launch). But also not every time, I.E. after uninstalling and running the app from Android Studio sometimes the error occurs and sometimes it doesn't.

```
BroadcastReceiver receiver;
public void DownloadListener(final String ZipFile) {
  receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();

      if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
        long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);

        DownloadManager.Query query = new DownloadManager.Query();
        query.setFilterById(downloadReference);
        Cursor c = downloadManager.query(query);

        if (c.moveToFirst()) {
          int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
          if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
            DismissProgressDialog();
            ShowProgress("Almost Done", "Unzipping And Installing Database", pd.STYLE_SPINNER);
          }
        }
      }
    }
  };

  context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

```

In the manifest:

```
<receiver
  android:name="com.pushnotification.GcmBroadcastReceiver"
  android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <category android:name="com.geovision.ffmsnativeprototype" />
  </intent-filter>
</receiver>

<service android:name=".WebServiceCommunication.SystemDatabaseService" />

```

After commenting out the line `setResultCode(Activity.RESULT_OK);` as recommended by the answer to [another question](https://stackoverflow.com/questions/23835970/broadcastreceiver-trying-to-return-result-during-a-non-ordered-broadcast-packa) the IntentService for push notification received a notification with this content

```
From-google.com/iid-Title-null-Message-null-ExtraData-null

```

My case is the same as [Weird push message received on app start](https://stackoverflow.com/questions/30479424/weird-push-message-received-on-app-start)