I need to run a service each night at midnight. I would like to use the AlarmManager to do this.
Can you give me some guidance of how to make it work correctly?
alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, System.currentTimeMillis(), AlarmManager.INTERNAL_DAY, serviceIntent);
Perhaps I need to use a Calendar object to specify the time? Thanks for any help!
setInexactRepeating(), as the name suggests, is inexact. Bear in mind that it might run somewhat before or after midnight.To determine when midnight is, use a
Calendarobject. Then callgetDate()to get aDateandgetTime()on theDateto get the proper millisecond value for yoursetInexactRepeating()call.