Answer the question
In order to leave comments, you need to log in
Why don't push notifications always open different activities?
I implement a chat in Android, when a new message arrives, I show a notification next. way:
private void showNotification(Note note) {
Intent viewIntent = new Intent(this, ChatActivity.class);
long roomServerId = note.getRoom().getServerId();
viewIntent.putExtra(ChatActivity.KEY_ROOM_SERVER_ID, roomServerId);
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent viewPendingIntent = PendingIntent.getActivity(this, (int) roomServerId, viewIntent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(note.getRoom().getInterlocutor().getFullName())
.setSound(alarmSound)
.setContentText(note.getText())
.setContentIntent(viewPendingIntent)
.setAutoCancel(true);
notificationManager.notify((int) roomServerId, notificationBuilder.build());
}
Answer the question
In order to leave comments, you need to log in
Added one more flag Intent.FLAG_ACTIVITY_CLEAR_TOP and it works:
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question