Firebase firing too many alarms
Asked Answered
G

1

11

I already have an alarm that fires daily which has FLAG_UPDATE_CURRENT. This is the log from developer's console.

java.lang.SecurityException: !@Too many alarms (500) registered from pid 32326 uid 10206
    at android.os.Parcel.readException(Parcel.java:1540)
    at android.os.Parcel.readException(Parcel.java:1493)
    at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:206)
    at android.app.AlarmManager.setImpl(AlarmManager.java:428)
    at android.app.AlarmManager.set(AlarmManager.java:215)
    at com.google.firebase.iid.FirebaseInstanceIdService.zzagl(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceIdService.zzd(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceIdService.zzm(Unknown Source)
    at com.google.firebase.iid.zzb$2.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)

I am using Firebase 9.6.1.


UPDATE:

public static void setAlarm(Context context, boolean isSet) {
  try {
     AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
     Intent intent = new Intent(context, AlarmReceiver.class);

     boolean isWorking = (PendingIntent.getBroadcast(context,
                SettingsActivity.REQUEST_CODE, intent, PendingIntent.FLAG_NO_CREATE) != null);

     if (isSet && !isWorking) {
        PendingIntent sender = PendingIntent.getBroadcast(context,
                                   SettingsActivity.REQUEST_CODE, intent, 
                                   PendingIntent.FLAG_UPDATE_CURRENT);

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());

        calendar.set(Calendar.HOUR, 10);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                               AlarmManager.INTERVAL_DAY, sender);
      } else {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
                                      SettingsActivity.REQUEST_CODE, intent,
                                      PendingIntent.FLAG_CANCEL_CURRENT);
        am.cancel(pendingIntent);
        pendingIntent.cancel();
      }
  } catch (Exception e) {
      Crashlytics.logException(e);
  }
}
Garden answered 17/10, 2016 at 7:9 Comment(6)
This question will help you #29345471Indigent
No, it won't. Firstly it doesn't mention anything about firebase. Secondly, I am already using FLAG_UPDATE_CURRENT.Garden
It seems like internal bug in firebase. As mentioned in firebase google group (groups.google.com/forum/#!topic/firebase-talk/Q_zycHnTGu0) the problem appears (at most for Samsung devices) even if you don't use any alarms in your app.Roane
Are you testing it in Samsung+Lollipop . And also share your code for alarmDistemper
Crashes both on Samsung's lollipop and marshmallow.Downgrading to firebase 9.4.0 solves the crash issue. Updated alarm code.Garden
Your problem are solved: https://mcmap.net/q/1159647/-firebase-messaging-quot-too-many-alarms-quot-on-samsung-39-s-android-devicesBlubberhead
G
2

According to this thread, the bug has been fixed by the Firebase team in the 10.0 release. Release notes are here.

Gospel answered 22/11, 2016 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.