title: BroadcastReceiver trying to return result during a non-ordered broadcast Weird Error
body: <p>This error started occurring when the app is launched for the first time even though I am not sending a push notification:</p>
  
  <pre><code> 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)
  </code></pre>
  
  <p>The code for the BroadcastReceiver:</p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>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));
  }
  </code></pre>
  
  <p>In the manifest:</p>
  
  <pre><code>&lt;receiver
    android:name="com.pushnotification.GcmBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" &gt;
    &lt;intent-filter&gt;
      &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
      &lt;category android:name="com.geovision.ffmsnativeprototype" /&gt;
    &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  
  &lt;service android:name=".WebServiceCommunication.SystemDatabaseService" /&gt;
  </code></pre>
  
  <p>After commenting out the line <code>setResultCode(Activity.RESULT_OK);</code> as recommended by the answer to <a href="https://stackoverflow.com/questions/23835970/broadcastreceiver-trying-to-return-result-during-a-non-ordered-broadcast-packa">another question</a> the IntentService for push notification received a notification with this content</p>
  
  <pre><code>From-google.com/iid-Title-null-Message-null-ExtraData-null
  </code></pre>
  
  <p>My case is the same as <a href="https://stackoverflow.com/questions/30479424/weird-push-message-received-on-app-start">Weird push message received on app start</a></p>