android多个通知

android多个通知,android,notifications,Android,Notifications,嗨,我是android新手,我正在开发一个提醒,它有三类:第一类是设置多个预约提醒,第二类是多个每月(账单)提醒,第三类是多个每日(医药)提醒,都在同一个项目中 一切正常,但我有一个问题,当我设置三个提醒时,他们都会按照LogCat上显示的那样准时启动,但问题是当药物通知出现在酒吧通知中,然后账单提醒会启动,此账单通知将取代幻灯片通知上的现有药品提醒,反之亦然。约会提醒通知工作正常 我需要在幻灯片向下通知中包含所有三个类别的通知,而不需要将现有类别替换为其他类别 所以我认为问题出在通知的代码中,

嗨,我是android新手,我正在开发一个提醒,它有三类:第一类是设置多个预约提醒,第二类是多个每月(账单)提醒,第三类是多个每日(医药)提醒,都在同一个项目中

一切正常,但我有一个问题,当我设置三个提醒时,他们都会按照LogCat上显示的那样准时启动,但问题是当药物通知出现在酒吧通知中,然后账单提醒会启动,此账单通知将取代幻灯片通知上的现有药品提醒,反之亦然。约会提醒通知工作正常

我需要在幻灯片向下通知中包含所有三个类别的通知,而不需要将现有类别替换为其他类别

所以我认为问题出在通知的代码中,但我无法找出代码中的问题

我为每个类别提供单独的提醒服务。有人能看一下并告诉我问题出在哪里吗

这是药物提醒服务

public class Medicines_ReminderService extends WakeReminderIntentService {

    public Medicines_ReminderService() {
        super("ReminderService");
            }

    @Override
    void doReminderWork(Intent intent) {
        Log.d("MedicinesReminderService", "Doing work.");
        Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID_MEDS);

        NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(this, MedicinesEdit.class); 
        notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID_MEDS, rowId); 
        int N_Med_requestCode = rowId.intValue();
        PendingIntent pi = PendingIntent.getActivity(this, N_Med_requestCode, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 



        Notification note=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_reminder_message), System.currentTimeMillis());
        note.setLatestEventInfo(this, getString(R.string.notify_new_medicine_reminder_title), getString(R.string.notify_new_reminder_message), pi);
        note.defaults |= Notification.DEFAULT_SOUND; 
        note.flags |= Notification.FLAG_AUTO_CANCEL; 

        int id = (int)((long)rowId);
        mgr.notify(id, note); 


    }
}
这是账单提醒服务

public class Bills_ReminderService extends WakeReminderIntentService {

    public Bills_ReminderService() {
        super("ReminderService");
            }


    @Override
    void doReminderWork(Intent intent) {
        Log.d("BillsReminderService", "Doing work.");
        Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID_BILLS);    

        NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(this, BillsEdit.class); 
        notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID_BILLS, rowId); 
        int N_Bill_requestCode = rowId.intValue(); 
        PendingIntent pi = PendingIntent.getActivity(this, N_Bill_requestCode, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);  

        Notification note=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_reminder_message), System.currentTimeMillis());
        note.setLatestEventInfo(this, getString(R.string.notify_new_bill_reminder_title), getString(R.string.notify_new_reminder_message), pi);
        note.defaults |= Notification.DEFAULT_SOUND; 
        note.flags |= Notification.FLAG_AUTO_CANCEL; 

        int id = (int)((long)rowId);
        mgr.notify(id, note);



    }
}
提前谢谢

致以最良好的祝愿,
zoza

您正在使用行ID作为“唯一”标识符,而在您拥有的3个服务之间,行ID可能不是唯一的

i、 e

管理通知“ID在应用程序中唯一标识通知。如果您需要更新通知或(如果您的应用程序管理不同类型的通知),则该ID是必需的当用户通过通知中定义的意图返回应用程序时,选择适当的操作。“

如果每个类别只需要一个通知,则可以使用:

    int BillsID=1;
    int MedsID=2;

    mgr.notify(BillsID, note);
    mgr.notify(MedsID, note);
或者,如果您确实需要每个通知基于其行号,则需要添加一个区分符,以避免将相同的id分配给不同的通知

    int BillsID=100000;
    int MedsID=200000;
    mgr.notify(BillsID+RowID, note);
    mgr.notify(MedsID+RowID, note);
    int BillsID=100000;
    int MedsID=200000;
    mgr.notify(BillsID+RowID, note);
    mgr.notify(MedsID+RowID, note);