2

I want to show a notification at a specific date and I use Calendar object:

    Calendar calendar = Calendar.getInstance();
    calendar.set(Year, Month, Day, Hours, Minutes, Seconds);
    long when = calendar.getTimeInMillis();

And I use a AlarmManager:

        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent i = new Intent(this, NotificationsService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    am.cancel(pi);
    am.set(AlarmManager.RTC_WAKEUP, when, pi);

But this not show a correct miliseconds, if I use:

am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pi);

Show correct notification, but if I use a when flag not show a correct miliseconds to notification. Why? Someone help me please. thanks

Edit: (Solve problem)

The problem was that the Month in Calendar is previous at actual (January = 0, February = 1, ...)

nss
  • 121
  • 2
  • 11

1 Answers1

0

I'd recommend looking here for an example of how to run a service at a specific date/time: How to run a service every day at noon, and on every boot

One important thing you gotta remember with alarmmanager is that all values are forgotten on phone restart. Link provides a solution for that as well.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Thanks, I don't know about alarmmanager fails. But this link don't help me, because I can show notification in a specific date (Year, Month, Day, Hours, Minutes, Seconds) and this link have code to every days. I don't want use "AlarmManager.setRepeating..." I want "AlarmManager.set...", thanks – nss Jun 04 '13 at 13:20
  • Thanks, I solve the problem. The problem was that the Month in Calendar is previous at actual (January = 0, February = 1, ...) – nss Jun 04 '13 at 16:39