I have 2 StatusBar Notification in my app. These notifications appear in the same time in app, and I can see only the last notification. And, if I press the Button Clear, both of them are cleared. How to work with more than one notification in android?
The second question is how to display the text of notification on multiple rows. I can see only the beginning of the text.
Here is my code :
for the first notification :
private void setNotifiy() {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "You have a notification";
CharSequence contentTitle = "You are close to " + name_shop + "!!!";
CharSequence contentText = "So,you can go for shopping:)";
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.icon,
NotificationTicket, when);
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, ShopsOnMap.class);
System.out.println("DDDDd" + lat_choose + "!!!");
notificationIntent.putExtra("latshop", lat_choose);
notificationIntent.putExtra("longshop", long_choose);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
and for second notification :
private void hey(String list) {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "Hey";
CharSequence contentTitle = "Shopping!!";
CharSequence contentText = "Today,you must go for shopping for your list ' "
+ list + "'" + "Don't forget!!!";
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.icon,
NotificationTicket, when);
Context context = getApplicationContext();
Intent notifyIntent = new Intent(context, Lists.class);
PendingIntent intent =
PendingIntent.getActivity(Lists.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, contentTitle, contentText, intent);
notificationManager.notify(NOTIFICATION_ID, notification);
notificationManager.notify(NOTIFICATION_ID, notification);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
I see your codes are using the same ID for both notifications.
As you might know, the answer is already on this documentation:
Creating Status Bar Notifications.
You may focus on two things covered on the documentation: