PendingIntent

AMS(Activity Manager Service)对PendingIntent 进行管理
PendingIntent 的使用场景:
1.使用 AlarmManager 设定闹钟
2.在系统状态栏显示 Notification
3.在桌面显示 Widget

初始化方法

// 获取 Broadcast 关联的 PendingIntent
PendingIntent.getBroadcast(Context context, int requestCode, Intent intent, int flags)

// 获取 Activity 关联的 PendingIntent
PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags)
PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags, Bundle options)
每次requestcode不同,就能产生多个Pendingintent.
flags对不同操作作标识.

// 获取 Service 关联的 PendingIntent
PendingIntent.getService(Context context, int requestCode, Intent intent, int flags)
//如果新请求的 PendingIntent 发现已经存在时,取消已存在的,用新的 PendingIntent 替换
int FLAG_CANCEL_CURRENT

//如果新请求的 PendingIntent 发现已经存在时,忽略新请求的,继续使用已存在的。日常开发中很少使用
int FLAG_NO_CREATE

//表示 PendingIntent 只能使用一次,如果已使用过,那么 getXXX(...) 将会返回 NULL 
//也就是说同类的通知只能使用一次,后续的通知单击后无法打开。
int FLAG_ONE_SHOT

//如果新请求的 PendingIntent 发现已经存在时, 如果 Intent 有字段改变了,这更新已存在的 PendingIntent
int FLAG_UPDATE_CURRENT
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容