java.lang.SecurityException: !@Too many alarms (500) 从pid 10790 uid 10206 注册 [英] java.lang.SecurityException: !@Too many alarms (500) registered from pid 10790 uid 10206

查看:30
本文介绍了java.lang.SecurityException: !@Too many alarms (500) 从pid 10790 uid 10206 注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用警报管理器安排警报时收到此错误

I'm getting this error at the time of Schedule alarm using Alarm Manager

am.setExact(AlarmManager.RTC_WAKEUP, timeMillis, pendingIntent);

错误如下

java.lang.SecurityException: !@Too many alarms (500) registered from pid 10790 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.setExact(AlarmManager.java:376)

为什么会出现此错误以及我们如何修复它.

Why this error is coming and how we can fix it.

推荐答案

与评论所暗示的不同,这可能不是你的错.这开始发生在我们 3 月中旬某个地方的生产代码中,这只发生在三星的 Lollipop 上,Lollipop 最近才开始推出.

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.

就像@goncalossilva 所说的问题是由于使用了FLAG_CANCEL_CURRENT,三星似乎对警报数量设置了 500 个上限,其他供应商没有这个限制.

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.

当创建带有 FLAG_CANCEL_CURRENTPendingIntent 时,它将取消挂起的意图(显然)不会取消警报(也很明显),稍后如果您取消警报使用新的待处理意图不会取消警报(不太明显,因为 Intent.filterEquals 应该是 true).话虽如此,因为挂起的意图被取消了,旧的警报实际上不会触发,所以不必担心通过切换 FLAG_UPDATE_CURRENT 来引入错误.

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.

关于更改为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.

您可以尝试使用此代码重现该问题,然后更改为 FLAG_UPDATE_CURRENT 以查看会发生什么.您还应该运行 "adb shell dumpsys 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);
    } 

这篇关于java.lang.SecurityException: !@Too many alarms (500) 从pid 10790 uid 10206 注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆