Repeat alarm manager in exact interval in API => 19?

I had a huge read and I think there is no clear / complete answer to this question.

First you need to clarify: this issue does not concern battery saving on the phone, but more about the exact time and I'm new to Android.

Now let me explain this question in more detail. I have an Alarm dispatcher that will call a toast (for simplicity) for a given interval (every 2 minutes) manager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(), interval, pendingIntent); The above will refer to the onReceive () method of BroadcastReciver.

public class AlarmReceiver extends BroadcastReceiver  {
@Override
public void onReceive(Context context, Intent intent) {
    //Toast ....bala blah
   }}

Now it was the exact interval for API <19, however In API => 19 setRepeating () is no longer accurate! I found that some people suggested (in other forms) to use setExact (). but there is no example or clear explanation of how to use setExact () in Interval (or I could not find this). As far as I understood, setExact () is disabled, unlike setRepeating (), so, according to some others, the next graph should be set via onReceive () (again, I could not find an example; (Anyway, this is where I am now and I really appreciate any comment or suggestion, link or example ...

I hope I asked my question quite clearly, by the way, if there is a different approach to this (to complete the task at exact intervals in the API> 19, please let me know) Thank you very much

+4
1

setExact setRepeating.

void scheduleAlarm(Context context) {
    AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Intent yourIntent = new Intent();
    //TODO configure your intent
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, MyApplication.ALARM_REQUEST_CODE, yourIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmMgr.setExact(AlarmManager.RTC_WAKEUP, timeToWakeUp, alarmIntent);
}

:

  • ( )
  • onReceive BroadcastReceiver.

      public class AlarmReceiver extends BroadcastReceiver  {
      @Override
      public void onReceive(Context context, Intent intent) {
        //TODO process alarm
        scheduleAlarm(context);
      }}
    
+7

All Articles