I know that there are similar questions around but none helped me... I'm trying to set a repeating alarm to fire a broadcast receiver, which will in turn fire an intentservice. I know about doze mode postponing alarms and I don't mind. At first the alarm works fine but after a while it isn't delivered at all. This is how I set the alarm:
public static void startRepeated(Context context){
Intent intent=new Intent(context,MyService.class);
//starting it manually first because API 19+ doesn't deliver exact alarms, but we want a run now
context.startService(intent);
intent = new Intent(context,ServiceReceiver.class);
int minutes=PreferenceManager.getDefaultSharedPreferences(context).getInt("timer",R.integer.timer_def);
final PendingIntent pendingIntent= PendingIntent.getBroadcast(context.getApplicationContext(),1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager=(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),minutes*60000,pendingIntent);
}
The receiver's (WakefulBroadcastReceiver) onreceive method:
@Override
public void onReceive(Context context, Intent intent) {
Log.e("SERV-RECEIVER ","triggered");
startWakefulService(context,new Intent(context,MyService.class));
}
Note that when this happens, I don't the see SERV-RECEIVER log so not even the receiver is fired. My intent service opens a SQLite db, does some work, closes it and then releases the wakelock. The receiver is registered in android manifest without intents:
<receiver android:name=".ServiceReceiver" android:enabled="true"/>
I tried to set the device to doze mode and the app to standby manually using adb commands, and after I wake the device up it still works fine. The problem occurs only if I leave it for some time. Using adb shell dumpsys alarm, I noticed that this is always visible (even after the alarm stops
trigerring):
u0a229:com.isoc.android.monitor +2s384ms running, 37 wakeups:
+2s384ms 37 wakes 37 alarms, last -6m33s804ms:
*walarm*:com.isoc.android.monitor/.ServiceReceiver
But this disappears when the problem occurs (from the batch section):
ELAPSED_WAKEUP #0: Alarm{99ac864 tag *walarm*:com.isoc.android.monitor/.ServiceReceiver type 2 when 340221779 com.isoc.android.monitor}
tag=*walarm*:com.isoc.android.monitor/.ServiceReceiver
type=2 whenElapsed=-971ms when=-5s971ms
window=+3m45s0ms repeatInterval=300000 count=0 flags=0x0
operation=PendingIntent{14dfacd: PendingIntentRecord{82c6f82 com.isoc.android.monitor broadcastIntent}}
I noticed that on my android API 15 mobile this problem doesn't happen though. Only on my Android marshmallow phone...Any help would be greatly appriciated :) Thanks