Source: http://stackoverflow.com/questions/29344971/java-lang-securityexception-too-many-alarms-500-registered-from-pid-10790-u
Unlike what the comment suggests, this might not be your fault. This started happening for us in production code somewhere mid March, this only happens on Samsung with Lollipop which only recently started to be rolled out.
Update: This issue finally happened on one of the phones we have available.
like @goncalossilva said the problem is due to use of FLAG_CANCEL_CURRENT, it seems that Samsung introduces a cap of 500 on the amount of alarms and no other vendor have this limit.
when creating a PendingIntent with FLAG_CANCEL_CURRENT it will cancel the pending intent (obviously) won't cancel the alarm (also obvious), later if you cancel the alarm using the new pending intent it won't cancel the alarm (less obvious as Intent.filterEquals should be true). That being said, because the pending intent was canceled the old alarm won't actually fire, so there it no fear in introducing bugs by switching FLAG_UPDATE_CURRENT.
regarding the need to restart the device after changing to FLAG_UPDATE_CURRENT, you don't have to restart you just need to wait for one of the alarms to fire so that you have a new slot for a new alarm.
you can try this code to reproduce the issue, then change to FLAG_UPDATE_CURRENT to see what happens. you should also run "adb shell dumpsys alarm" to see all the generated alarms
AlarmManager alarmManager =
(AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
for (int i = 0; i<1000; i++)
{
Intent intent = new Intent("FOOFOOFOO");
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.cancel(pendingIntent);
long firstTime = SystemClock.elapsedRealtime() + 1000;
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime, pendingIntent);
}
...
Using adb shell dumpsys alarm I found out that our app had been leaking alarms all along, it just wasn't visible before this. Changing FLAG_CANCEL_CURRENT to FLAG_UPDATE_CURRENT and making sure the PendingIntents were identical (extracting their creation to a common method) solved it for us. – Sampo Jul 30 '15 at 10:41
이곳도 확인 해보시기 바랍니다.
Source: https://github.com/AltBeacon/android-beacon-library/issues/184
starts the alarm with:
PendingIntent.getBroadcast(mContext, 0, wakeupIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
and cancels it with:
long milliseconds = Long.MAX_VALUE; // 2.9 million years from now
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(
Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() +
milliseconds, getWakeUpOperation());
i hope this may help you.