【问题标题】:Multiple alarms with AlarmManager in AndroidAndroid中使用AlarmManager的多个警报
【发布时间】:2013-05-09 02:32:46
【问题描述】:

SO 上的所有帖子都使用 PendingIntent.getBroadcast()。我们可以使用 PendingIntent.getService() 设置多个警报吗?我尝试使用 PendingIntent.getService() 进行单个警报的代码。它工作正常。但我不知道如何使用 PendingIntent.getService() 设置多个警报。并且使用 PendingIntent.Broadcast() 甚至不会发出一个警报。

请高手帮忙! :)

【问题讨论】:

    标签: android alarmmanager


    【解决方案1】:

    我们可以使用 PendingIntent.getService() 设置多个警报吗?

    当然,只要他们不使用_WAKEUP 警报。可靠的_WAKEUP 警报的秘诀需要广播PendingIntent

    但我不知道如何使用 PendingIntent.getService() 设置多个警报。

    使用任何PendingIntent 设置多个警报的方式相同:调用set()setRepeating()setInexactRepeating()不同 PendingIntent。 “不同”是指它的类型必须不同(活动、服务或广播),或者Intent 对象不能与filterEquals() 匹配,或者PendingIntent 工厂方法中使用的请求代码(例如, getService()) 的第二个参数必须不同。

    【讨论】:

    • 我正在使用 getBroadcast()、不同的 Intent 和不同的 PendingIntent 请求代码,但仍然只触发一个警报。知道为什么吗?
    • @Dpedrinha:使用adb shell dumpsys alarm 并确认您实际上安排了多个警报。除此之外,您还需要使用minimal reproducible example 提出单独的问题。
    猜你喜欢
    • 1970-01-01
    • 2013-01-07
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多