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

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

问题描述

使用警报管理器在计划警报时收到此错误

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的三星上发生。

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.

在创建 PendingIntent时 FLAG_CANCEL_CURRENT 会取消挂起的意图(显然)不会取消警报(也很明显),稍后,如果您使用新的待处理意图不会取消警报(不太明显,因为 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警报 以查看所有生成的警报

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:!@从pid 10790 uid 10206注册的警报太多(500)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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