Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android repeating alarm minimum interval?

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);
like image 912
Vee Doo Avatar asked Oct 30 '22 14:10

Vee Doo


1 Answers

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" />
like image 111
poqueque Avatar answered Nov 11 '22 11:11

poqueque