Reputation: 4619
Scenario 1 - App is open, receive pendingintent in notification and when notification is clicked,
opens activity with new content, every pendingintent notification received after the first works in a similar fashion
.
Scenario 2 - App is closed (not running), receive pendingintent in notification and when notification is clicked,
opens activity with new content, every pendingintent notification received after the first does not work in a similar fashion (doesn't launch activity)
.
Code of Pending Intent: Intent nIntent = new Intent(getApplication(), ChatActivity.class);
nIntent.putExtra("chattingFrom", chattingToName);
nIntent.putExtra("chattingToName", chattingFrom);
nIntent.putExtra("chattingToDeviceID", chattingFromDeviceID);
nIntent.putExtra("chattingFromDeviceID", chattingToDeviceID);
NOTIFICATION_ID = NOTIFICATION_ID + 1;
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, nIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notify);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Chat App")
.setStyle(new NotificationCompat.BigTextStyle().bigText("New message from " + chattingFrom + ": " + msg))
.setContentText("New message from " + chattingFrom + ": " + msg)
.setAutoCancel(true)
.setTicker("New message from " + chattingFrom)
.setSound(sound);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Main Problem: When user clicks notification (app is closed/not running), activity opens with new content(first click), every notification after that does not work(subsequent clicks).
Everything works when app is open, and then notification comes in.
Upvotes: 2
Views: 388
Reputation: 4619
I added a dummy action to my intent, see below:
For example nIntent.setAction("foo")
Upvotes: 1
Reputation: 1570
I think you should take out PendingIntent.FLAG_ONE_SHOT
since this would render the PendingIntent usable only once.
Upvotes: 1