I set my repeating alarm to trigger every 2 minutes but instead it triggers exactly every 5 minutes. I have tested different intervals under 5 minutes but this behavior does not change. Is there a minimum Android enforces? I am using 4.1.2. Here is my code
Intent intent = new Intent(context, UpdateAlarmReceiver.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, 120000, alarmIntent);
I fixed that problem adding a WakeLock:
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
WakeLoc wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelock");
wakeLock.acquire(180000); //Auto-close in three minutes
You should also add permissions to Manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With