android - PendingIntent 与 PendingIntent.FLAG_NO_CREATE

标签 android alarmmanager android-pendingintent

我想了解 PendingIntent.FLAG_NO_CREATE 的行为。我想知道什么时候它会返回 null 以及什么时候不会。 这是事件发生的顺序:

alarmIntent = new Intent(context, AlarmReceiver.class)
pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                            calendar.getTimeInMillis(),
                            AlarmManager.INTERVAL_DAY, pendingIntent);

现在,当我运行时:

PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE)

它返回一个非空值。 现在我的问题是它返回一个非空值,因为我使用 PendingIntent.FLAG_UPDATE_CURRENT 创建了一个endingIntent,还是因为我调用了manager.setInexactRepeated(...)?

最佳答案

据我所知,只有当系统找不到 Intent 时,PendingIntent.FLAG_NO_CREATE才会返回null。

如果系统没有找到它,它不会创建一个,因为您标记为“不创建”,系统将返回 null。

如果您已经先创建了一个 Intent 并将其传递给警报管理器,系统将返回一个非空值,直到该警报到期或直到您取消该警报。

关于android - PendingIntent 与 PendingIntent.FLAG_NO_CREATE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35794364/

相关文章:

java - 如何从 json 字符串中获取值

android - 闹钟没有唤醒手机

Android 警报管理器工作,但延迟

android - 如何保护后台服务/警报在自定义操作系统(如 oppo - coloros、vivo-funtouch os、Xiomi-MIUI os)中被杀死?

android - 两个按钮,一个 Activity

android - 待定 Intent 不起作用

java - 使用 PendingIntent 停止服务

android - java.lang.NoSuchMethodError : org. apache.commons.codec.binary.Base64.encodeBase64

android - Selenium 2.41 - 无法启动 Firefox

java - 在 Android 的房间数据库中插入复合键的重复值后应用程序崩溃