12

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 :

  1. Flag PendingIntent.FLAG_CANCEL_CURRENT
  2. Cancelling the alarm before setting
  3. 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 ?

rd7773
  • 409
  • 3
  • 13
  • Possible duplicate of https://stackoverflow.com/questions/29344971/java-lang-securityexception-too-many-alarms-500-registered-from-pid-10790-u – AouledIssa Apr 14 '20 at 12:31
  • 1
    Does this answer your question? [java.lang.SecurityException: !@Too many alarms (500) registered from pid 10790 uid 10206](https://stackoverflow.com/questions/29344971/java-lang-securityexception-too-many-alarms-500-registered-from-pid-10790-u) – AouledIssa Apr 14 '20 at 12:31
  • I'm having similar issue (Oppo devices with Android 7.1.1 & TCL devices with Android 10). The Android source code that throws this exception is here (line 1762): https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/services/core/java/com/android/server/AlarmManagerService.java – sagis May 31 '20 at 09:42
  • 1
    Did you find any solution ? Please post answer (if any) – Giru Bhai Jan 08 '21 at 11:58
  • I'm looking for a solution too. have you figured out any approach? Thanks! – Agustín Alcázar Jul 28 '22 at 06:37

0 Answers0