2

I would like to set a notification at 8th of every month.

This is what i did:

Intent myIntent = new Intent(remember.this, receiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(remember.this, 0, myIntent, 0);

        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);


        // Set the alarm to start at approximately 8th of 
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.DAY_OF_MONTH, 8);


        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY*30, pendingIntent);

However what i got was a constant notification within minutes. And this does not go away.

Would appreciate your help here as i really do not know where went wrong.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • I will set alarm of date 8 at current month, which is past date and will trigger the alarm. And what is 'this does not go away'? – Harin Apr 29 '15 at 12:44
  • You have set alarm for April 8th which is already past hence the alarm is triggering immediately. You can debug by printing `System.out.println(calendar.getTime());` which will give `Wed Apr 08 18:22:13 IST 2015` – Psypher Apr 29 '15 at 12:53
  • 'this does not go away' == Means the notification keeps popping out even though user cancels it. – user4846394 Apr 29 '15 at 13:10
  • @user4846394 Can you also post the code used to cancel the alarm – Psypher Apr 30 '15 at 01:45

1 Answers1

-1

Set calendar to upcoming 8th of the month.

alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis() , pendingIntent);

Inside receiver.class

public void onReceive(Context context, Intent intent) {
//do action needed
//invoke alarmManager in mainActivity
// cancel the previous alarm 
// set the new alarm for the next month
}
Rakhi
  • 81
  • 12