1

I have GCMIntentService implemented and whenever i get the push notification i need to show the notification in notification menu and open an activity with some bundle values in the intent. I can see the notification in the notification menu but clicking on it just doesn't do anything. Following is the code which i am using :-

  mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent i = new Intent(this, ChatDetail.class);
    Bundle b = new Bundle();
    b.putString("my_id", "5356b178b130a74a57019fe9");
    b.putString("you_id", youId);
    i.putExtras(b);
   //       PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
   //               new Intent(this, MainActivity.class), 0);
            PendingIntent contentIntent = PendingIntent.getActivity(this, 0,      
                    i,PendingIntent.FLAG_CANCEL_CURRENT );

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.pool_my_ride_icon)
    .setContentTitle("GCM Notification")
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(text))
    .setContentText(text);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

I can see the notification but when i click on it the notification menu slides up and doesn't do anything doesn't opens any activity. If i don't send any bundle in the extras then i can open the activity but when i send bundle values then i can't open the activity.

Thanks in advance

abhishek
  • 1,434
  • 7
  • 39
  • 71
  • Do you have any logging? Does the activity open at all? Put some log statements in the Activity to make sure it doesn't get started at all, and not crashing at some other point before the view can be displayed. Maybe also post your `onReceive()` code. – RoraΖ Jul 15 '14 at 19:26
  • No the activity doesn't opens at all – abhishek Jul 16 '14 at 01:05
  • hey abhishek show your stacktrace because when i tried it opened the activity when clicked on notification.. – williamj949 Jul 28 '14 at 07:55

2 Answers2

0

I'd try to add the extras to the intent one at a time :

i.putExtra("my_id", "5356b178b130a74a57019fe9");
i.putExtra("you_id", youId);
Eran
  • 387,369
  • 54
  • 702
  • 768
0

hey try this it worked for me

Intent i = new Intent(this, ChatDetail.class);
Bundle b = new Bundle();
b.putString("my_id", "5356b178b130a74a57019fe9");
b.putString("you_id", youId);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.putExtras(b);

the important point here is to send the additional flags to actually want your intent to be delivered

i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);

Just let me know if it worked for you!

williamj949
  • 11,166
  • 8
  • 37
  • 51