Android : Android onHandleIntent of GCMIntentService is called twice

on Wednesday, April 1, 2015


I need badly your help. I'm using GCM to send notifications to my users. However, when I receive the notification, onHandleIntent is being called twice as I checked my logcat for tracing.


This is my code:



public GCMIntentService() {
super("GCMIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {
Log.i("Notif", "GCM RECEIVER");
extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
Log.i(TAG, gcm.getMessageType(intent));

id = extras.getString("id");
todayCal = Calendar.getInstance();
// isNotified = false;
context = this;
notification_id = Integer.parseInt(id);
message = "test";
GcmBroadcastReceiver.completeWakefulIntent(intent);


}


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)));
setResultCode(Activity.RESULT_OK);
}
}


What seems to be the reason why it's getting called twice? I might have missed something.


I would gladly appreciate any kind of help. Thanks!


0 comments:

Post a Comment