Repeat alarm everyday at specific time (Alarm mana

2019-02-25 12:35发布

问题:

Hi I want my application to run at specific time daily. for this I am using below code. But it runs only for one time. Whats the mistake here how can i achieve this task.

AlarmManager alarmMgr0 = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent0 = new Intent(this, ActivityStarter.class);
PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, intent0, 0);
Calendar timeOff9 = Calendar.getInstance();
timeOff9.set(Calendar.HOUR_OF_DAY, 16);
timeOff9.set(Calendar.MINUTE, 13);
timeOff9.set(Calendar.SECOND, 0);
alarmMgr0.setRepeating(AlarmManager.RTC_WAKEUP, timeOff9.getTimeInMillis(),24*60*60*1000,pendingIntent0);

Any help please.

回答1:

Try this

 alarmMgr0 .setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY,
        AlarmManager.INTERVAL_DAY, intent);

refer this