Search code examples
javaandroidalarmmanager

AlarmManager to launch at certain time and repeating


I'm developing an app that has to run certain tasks when the user schedules them to be executed. I'm not sure what the following means in the Android docs.

triggerAtMillis: time in milliseconds that the alarm should go off, using the appropriate clock (depending on the alarm type)

This a quote from the set method documentation.

If I want the task to run at, for example, 27.10.2013 18:05, should I use 1382810700000 which is the date in milliseconds, or the time as milliseconds between now and that time?


Solution

  • If u want to create alarm for say for example-27.10.2013 18:05 you can use try something like this :

    Calendar cal = Calendar.getInstance();
    cal.set(year, month, day, hourOfDay, minute, second);
    

    Alarm Service:

    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, cal .getTimeInMillis(), pendingIntent);