0

I posted a question here however I could not get answer to that but basically this question is heart of that and if someone can clarify this to me can hit two birds with one stone!

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);} 

above code will trigger myAlarmReceiver class which extended BroadcastReceiver. Inside its onReceive() method I need to run again this alarm manager after exact two minutes.

Can any one help please?

Community
  • 1
  • 1
bastami82
  • 5,955
  • 7
  • 33
  • 44
  • What is your min and max SDK? You can try setRepeating - Depends a lot on what SDK you are targeting. You can check a sample [here](http://stackoverflow.com/questions/21461191/alarmmanager-fires-alarms-at-wrong-time/21461246#21461246) – Skynet Feb 06 '15 at 17:20
  • thanks for reply Skynet, it is API19+ , setRepeating is not exact enough on API19 above sadly. – bastami82 Feb 06 '15 at 17:25
  • Then you can call scheduleAlarm(Context context) from your onReceive() and set the time + 2 minutes. You can pass timeToWakeUp as an additional parameter to scheduleAlarm – Skynet Feb 06 '15 at 17:28
  • Sadly polling (periodically blindly check something ) programs are silent battery and data usage killers. If your checking something on the interweb for changes consider using https://developer.android.com/google/gcm/index.html GCM to alert the device there is new data. If your checking something that changes on the mobile device including the device location, connectivity status, battery level, wifi, sqlite database, screen on/off, etc. use the broadcast receiver. – danny117 Feb 06 '15 at 17:59
  • Check this one - https://stackoverflow.com/questions/28269752/repeat-alarm-manager-at-exact-interval-in-api-19 – Sanved Jul 31 '17 at 16:23

0 Answers0