I will spend a lot of time to solve my problem. I wrote a messenger client in android. My application receives an income message and prepares a notification. the notification panel displays each income message in the notification item. when you click on the notification item, it will open the conversation activity to list all messages from the very beginning until now. all dose is perfect, but when I click another item in the notification bar, nothing happens! (he should reload the data for another conversation). This is my notification code:
private void showNotification(String message, Class activity, Message messageObject) { //Get the Notification Service NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence text = message;//getText(R.string.service_started); Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent callbackIntent = new Intent(context, activity); if(messageObject != null) { callbackIntent.putExtra("conversation", MessageManager.getProvider().getConversation(messageObject.getConversationId())); } //callbackIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); int myUniqueValue = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(context, myUniqueValue, callbackIntent, PendingIntent.FLAG_ONE_SHOT); notification.setLatestEventInfo(context, messageObject.getFrom(), text, contentIntent); notificationManager.notify(messageObject.getFrom(), myUniqueValue, notification); }
This is the code block for calling the showNotification function.
showNotification(message.getBody(), ConversationActivity.class, messageObject);
source share