Android 一个活动的多个通知

Android 一个活动的多个通知,android,Android,实际上,我的应用程序有一个活动。要创建通知,我必须传递挂起的活动意图 NotificationManager mgr=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Notification note=new Notification(mob.app.R.drawable.message,"Message!",System.currentTimeMillis()); // T

实际上,我的应用程序有一个活动。要创建通知,我必须传递挂起的活动意图

NotificationManager mgr=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        Notification note=new Notification(mob.app.R.drawable.message,"Message!",System.currentTimeMillis());
        // This pending intent will open after notification click
        PendingIntent i=PendingIntent.getActivity(this, 2,new Intent(this,SaleNotification.class),0);


        note.setLatestEventInfo(activity,messageHeading,message, i);

        //After uncomment this line you will see number of notification arrived
        note.number=notifyNumber;
        mgr.notify(0, note);
这里SaleNotification.class不是一个活动,它是一个简单的类。 在这种情况下,是否可以创建多个通知?如何创建?
提前谢谢

要获得单独的通知,您需要为每个通知使用不同的
ID

这是一个简单的示例:

private int SIMPLE_NOTFICATION_ID_A = 0;
private int SIMPLE_NOTFICATION_ID_B = 1;
然后

和显示通知:

private void displayNotification(String extra, String contentTitle, String contentText, Class<?> cls, int id) {     

  Notification notifyDetails = new Notification(R.drawable.icon, "New Alert!", System.currentTimeMillis());
  Intent intent = new Intent(this, cls);
  intent.putExtra("extra", extra);
  PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), id, intent, PendingIntent.FLAG_ONE_SHOT);
  notifyDetails.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
  mNotificationManager.notify(id, notifyDetails);
}
private void displayNotification(字符串额外、字符串contentTitle、字符串contentText、类cls、int id){
Notification notifyDetails=新通知(R.drawable.icon,“新警报!”,System.currentTimeMillis();
意向意向=新意向(本,cls);
意向。额外(“额外”,额外);
PendingEvent contentIntent=PendingEvent.getActivity(getApplicationContext(),id,intent,PendingEvent.FLAG_ONE_SHOT);
setLateStevenInfo(getApplicationContext(),contentTitle,contentText,contentIntent);
mNotificationManager.notify(id,notifyDetails);
}
private void displayNotification(String extra, String contentTitle, String contentText, Class<?> cls, int id) {     

  Notification notifyDetails = new Notification(R.drawable.icon, "New Alert!", System.currentTimeMillis());
  Intent intent = new Intent(this, cls);
  intent.putExtra("extra", extra);
  PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), id, intent, PendingIntent.FLAG_ONE_SHOT);
  notifyDetails.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
  mNotificationManager.notify(id, notifyDetails);
}