How to use setallowWhileIdle method for repetitive task in AlarmManager, because I think that is the only method that overcomes doze mode.
I need to work 24*7 task in repetitive mode, is there any example please help I am new to android
private void scheduleAlarm() {
try{
Intent intent = new Intent(getApplicationContext(), KeepAliveAlarmReceiver.class);
final PendingIntent pIntent = PendingIntent.getBroadcast(this,
KeepAliveAlarmReceiver.REQUEST_CODE,
intent, PendingIntent.FLAG_MUTABLE);
long firstMillis = System.currentTimeMillis();// alarm is set right away
AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP,firstMillis,60000, pIntent);
System.out.println("enters into alarm manager");
}catch (Exception e)
{
e.printStackTrace();
Toast.makeText(this, e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
I need to do like this on setallowwhileIdle method it doesn't support repeatetive task timer.
Please read this post by @lyc001. Android - Repeating Alarms Allowed While Idle
It says
You should use either of these APIs and "reschedule the alarm every time it fires". So, A alarm that registers another alarm, and so on.