Via http://jimmymouse.iteye.com/blog/760505
PendingIntent是一个Intent的描述、包装,给予了这个PendingIntent 的组件在指定的事件发生或指定的时间到达时启动Activty、Service或者Broadcast。
根据是要启动Activity、Service还是Broadcast分别对应一个获取PendingIntent的方法
public static PendingIntent getActivity(Context context, int requestCode,
Intent intent, int flags)
requestCode,
Intent intent, int flags)
public static PendingIntent getService(Context context, int requestCode,
Intent intent, int flags)
三个函数的参数都相同,其中最后一个参数flags在文档中是这样解析的:
flags: May beFLAG_ONE_SHOT,LAG_NO_CREATE,LAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.
目前为止只提供FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT这四个flag
FLAG_ONE_SHOT:this PendingIntent can only be used once. If set, after send() is called on it, it will be automatically canceled for you and any future attempt to send through it will fail.
FLAG_NO_CREATE:if the described PendingIntent does not already exist, then simply return null instead of creating it.
FLAG_CANCEL_CURRENT:if the described PendingIntent already exists, the current one is canceled before generating a new one. You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent; by canceling the previous pending intent, this ensures that only entities given the new data will be able to launch it. If this assurance is not an issue, consider FLAG_UPDATE_CURRENT.
FLAG_UPDATE_CURRENT: if the described PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.
上面4个flag中最经常使用的是FLAG_UPDATE_CURRENT,因为描述的Intent有更新的时候需要用到这个flag去更新你的描述,否则组件在下次事件发生或时间到达的时候extras永远是第一次Intent的extras。使用FLAG_CANCEL_CURRENT也能做到更新extras,只不过是先把前面的extras清除,另外FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT的区别在于能否新new一个Intent,FLAG_UPDATE_CURRENT能够新new一个Intent,而FLAG_CANCEL_CURRENT则不能,只能使用第一次的Intent。
另外两flag就比较少用,利用FLAG_ONE_SHOT获取的PendingIntent只能使用一次,即使再次利用上面三个方法重新获取,再使用PendingIntent也将失败,利用FLAG_NO_CREAT获取的PendingIntent若描述的Intent不存在则返回NULL值.
相关推荐
博客《详解PendingIntent》有问题的源码第二部分
这样我们就可以画出如下示意图:PendingIntent 只能通过下列的静态方法获取//获取Broadcast关联的PendingIntent PendingI
博客《详解PendingIntent》所涉及的源码,这是博客中所说的有问题的PendingIntent对应原源代码
NULL 博文链接:https://sunzone.iteye.com/blog/1998091
Android中pendingIntent的深入理解
PendingIntent 分别实现了Notification和sms短信发送的两个示例
NULL 博文链接:https://technicalsearch.iteye.com/blog/2007636
android的服务以及通知的小例子 个人存档 代码笔记见http://blog.sina.com.cn/s/blog_70356c200100y9pf.html
另一个是利用Intent传递广播的Intent的时候,传参数的时候,记得设置PendingIntent sender=PendingIntent.getBroadcast(context,0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);的PendingIntent.FLAG_UPDATE_...
Notification的用法和PendingIntent的使用
简单的总结了Intent和PendtingIntent的区别,经常与alermanger 和notificationmanager一起使用。
PendingIntent.FLAG_UPDATE_CURRENT);这句话的第二个参数 requestCode,我设置的值:0,由于我创建的三个通知,requestCode值相同,并且第四个参数PendingIntent.FLAG_UPDATE_CURRENT,导致后创建的通知会更新之前的...
自制发送短信程序--SmsManager与PendingIntent类的使用
当你启动这个小应用程序时,按下 MainActivity 上的START ACTIVITY A按钮。 然后按活动 A 上的NORMAL SWITCH -> B按钮。 活动堆栈如下所示: TaskRecord{217a0c5a #1150 A=nl.codestone.switchactivities U=0 sz=3...
主要介绍了Android中pendingIntent的深入分析的相关资料,需要的朋友可以参考下
PendingintengTest
本文实例讲述了Android编程实现PendingIntent控制多个闹钟的方法。分享给大家供大家参考,具体如下: 要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)来实现控制多...
根据本讲学习内容,学会运用AlarmManager和PendingIntent实现定时提醒功能。 (1) 提交的作业包中含有应用程序运行效果截图。
Android中PendingIntent的简要介绍.pdf 学习资料 复习资料 教学资源