@morepork answered correctly. Just answer this to add a piece of code.
This, of course, is not an ideal solution, but at the moment I have not found the best.
This is what my code looks like:
@Override public void onMessageReceived(String from, Bundle data) { if(!"MY_SENDER_ID".equals(from)) { data.putString("from", from); Intent intent = new Intent(); intent.putExtras(data); intent.setAction("com.google.android.c2dm.intent.RECEIVE"); intent.setComponent(new ComponentName(getPackageName(), "my.application.packageId.MyGcmListenerService")); GcmReceiver.startWakefulService(getApplicationContext(), intent); }
You must make sure that all Service Listeners defined in the joint manifest are run, and this Listener has the highest priority. I know what a limitation.
Edit: Just decompiled the com.google.android.gms.gcm.GcmReceiver class, it does nothing good than the previous GcmBroadcastReceiver. Just update the token. So it's best to use GcmBroadcastReceiver only when you need multiple callbacks.
source share