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

编程入门 行业动态 更新时间:2024-10-18 19:29:40
本文介绍了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_CURRENT 的 PendingIntent 时,它将取消挂起的意图(显然)不会取消警报(也很明显),稍后如果您取消警报使用新的待处理意图不会取消警报(不太明显,因为 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 注册

本文发布于:2023-11-27 04:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SecurityException   alarms   java   lang   uid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!