Using alarms with pending broadcasts, this was working as intended until recently a crash started appearing for RealMe devices running on Android 10 and few OPPO devices running on Android 7.1.1
Crash :
IllegalStateException: Maximum limit of concurrent alarms 500 reached for uid on AlarmManager.setRepeating()
StackTrace :
Caused by java.lang.IllegalStateException: Maximum limit of concurrent alarms 500 reached for uid: u0a336, callingPackage: com.example.your.app
at android.os.Parcel.createException + 2095(Parcel.java:2095)
at android.os.Parcel.readException + 2055(Parcel.java:2055)
at android.os.Parcel.readException + 2003(Parcel.java:2003)
at android.app.IAlarmManager$Stub$Proxy.set + 320(IAlarmManager.java:320)
at android.app.AlarmManager.setImpl + 709(AlarmManager.java:709)
at android.app.AlarmManager.setRepeating + 454(AlarmManager.java:454)
Setting alarm by using :
val pendingIntent = PendingIntent.getBroadcast(
applicationContext, 0,
Intent(applicationContext, MyBroadcastReceiver::class.java),
PendingIntent.FLAG_UPDATE_CURRENT )
alarmManager.setRepeating(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
INITIAL_DELAY,
ONE_MINUTE_MILLIS,
pendingIntent )
Also tried :
alarmManager.setExact(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
INITIAL_DELAY,
pendingIntent )
Also tried with and without :
- Flag
PendingIntent.FLAG_CANCEL_CURRENT
- Cancelling the alarm before setting
- Cancelling the pending intent before setting
Is this device and android version specific crash (98% on RealMe Android 10 devices), or is there anything i am missing here that could prevent this crash to occur ?