zoza
zoza

Reputation: 127

android multiple notifications

Hi I’m new to android and I’m developing a reminder that have three categories the first one is to set up multiple appointment reminders and the second one multiple monthly (bills) reminders, and the third one multiple daily (medicine) reminders all in the same project.

All working fine but I’m have a problem when I set the three reminders they all fires on time as it appears on LogCat but the problem is when the medicine notification appears in the bar notification and a bill reminder fires after that, this bill notification will replace the existing medicine reminder on the slide down notification and the vice versa. The appointment reminder notification is working ok.

i need to have the notification for all the three categories in the slide down notification without replacing an existing one with another.

So I think the problem is in the codes of the notification but I couldn’t figure out what’s the problem in my code.

I have separate reminder services for each category. can someone please look at it and tell me what the problem is?

This is the medicine reminder service

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); 


    }
}

And this is the bill reminder service

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);



    }
}

thanks in advance

best regards, zoza

Upvotes: 2

Views: 3549

Answers (1)

Kuffs
Kuffs

Reputation: 35661

You are using the row ID as the "unique" identifier when it probably is not unique between the 3 services you have.

i.e.

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

from the docs at http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Managing your Notifications "The ID uniquely identifies the notification from within your application. The ID is necessary if you need to update the notification or (if your application manages different kinds of notifications) select the appropriate action when the user returns to your application via the intent defined in the notification."

If you only need one notification for each category, you could use:

    int BillsID=1;
    int MedsID=2;

    mgr.notify(BillsID, note);
    mgr.notify(MedsID, note);

or if you really do need each notification to be based on its row number you need to add a differentiator to avoid the same id being assigned to separate notifications.

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

Upvotes: 4

Related Questions