First of all I know that this question has been asked a lot , and the only answer is to set an unique id for the manager and the pending Intent so I did:
here's a code:
@Override
public int onStartCommand(Intent i , int flags , int startId){
try{
//UnqueID = i.getExtras().getInt(PassedUNIQUEID);
UniqueID++;
Log.d("SERVICECHECK" , UniqueID + "");
mStopIntent = new Intent(this , Service_reminder.class);
sTimeUntilNotification = 0;
CalculateTimeInMilSeconds(i);
final String Title = i.getExtras().getString(PassedSharedPref);
final String Note = i.getExtras().getString(PassedName);
//
Intent notificationIntent = new Intent(Service_reminder.this, activity_todialog_notecontent.class);
notificationIntent.putExtra(activity_todialog_notecontent.EXTRA_SUBJECTNAME, Title);
notificationIntent.putExtra(activity_todialog_notecontent.EXTRA_CONTENT, Note);
PendingIntent contentIntent = PendingIntent.getActivity(Service_reminder.this, UniqueID , notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.iconsubjecttracker)
.setContentTitle(Title)
.setContentText(Note);
builder.setContentIntent(contentIntent);
builder.setAutoCancel(true);
Uri AlarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(AlarmSound);
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Log.d("SERVICECHECK" , sTimeUntilNotification + "");
CountDownTimer Timer = new CountDownTimer(sTimeUntilNotification , 1000) {
@Override
public void onTick(long millisUntilFinished) {
//manager.notify(0, builder.build());
}
@Override
public void onFinish() {
manager.notify(UniqueID, builder.build());
stopService(mStopIntent);
}
}.start();
}catch(NullPointerException e){
//handle
}
return START_STICKY;
}
It fires up no problem on the time , but the problem is when for example I set a reminder " to fire notification later " on a note and for example I put 2 minutes and then I go to the next note and put a reminder with and lets say a minute then the first fires up no problem and the second fires up and then updates the first ? so the user will see the last notification that was fired , I'm not sure how to fix this.
Edit:
well I'm lost , I've been trying to solve it for hours and nothing worked , from declaring a static variable and adding 1 everytime I call the service to putting an unique id in shared prefrences and load it and then update it, but nothing worked.
I edited the code to the latest thing I did which is again putting a static variable and adding one everytime since it's the cleanest solution in my opinion.
Hopefully I can find a solution tomorrow.
for anyone not wanting to read everything here's an example + a picture for what I did:
first the picture:
http://oi62.tinypic.com/2mrs9s0.jpg
as you can see I called start service twice one with 1 minute reminder and the other with 2 minutes reminder , the 1 and 2 are the Unique id , so it couldn't have used the same id.
an example of the problem:
I have a note that says " math " for example and I put a reminder after 2 minutes , and then another note that says " calculus " and I put a reminder after 1 minute , after 1 minute the notification of calculus pops with no problem , after 2 minutes only the sound pops but not the math notification , and it stays the same as if I only put a calculus note.
Edit 2:
I've solved it after using alarm manager instead of a counter down.