PendingIntent是一个特殊的Intent,实际上它像一个邮包,其中包裹着真正的Intent,当邮包未打开时,Intent是被“挂起”的,所以并不执行,

只有当邮包拆开时才会执行。它与Intent的区别在于:Intent 是及时启动,intent 随所在的activity 消失而消失。

  PendingIntent 可以看作是对intent的包装,通过getActivity,getBroadcast ,getService来得到pendingintent的实例,当前activity并不能马

上启动它所包含的 Intent, 而是在外部执行 pendingintent时再调用 Intent。

  正由于pendingintent中 保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行pendingintent里

的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。常和alermanger 和notificationmanager

一起使用。

  Intent一般是用作Activity、Sercvice、BroadcastReceiver之间传递数据,而Pendingintent,一般用在 Notification上,可以理解为延迟执行的

intent,PendingIntent是对Intent一个包装。

  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的区别在于是否创建一个新的Intent,FLAG_UPDATE_CURRENT能够创建一个新的Intent,而FLAG_CANCEL_CURRENT

则不能,只能使用第一次的Intent。

  另外两flag就比较少用,利用FLAG_ONE_SHOT获取的PendingIntent只能使用一次。利用FLAG_NO_CREAT获取的 PendingIntent若描述的

Intent不存在则返回NULL值.

pendingIntent的FLAG标签:的更多相关文章

  1. dedecms flag标签属性

    头条[h] flag='h' 推荐[c] flag='c' 幻灯[f] flag='f' 特荐[a] flag='a' 滚动[s] flag='s' 加粗[b] flag='b' 图片[p] flag ...

  2. Go_16:GoLang中flag标签使用

    正如其他语言一样,在 linux 系统上通过传入不同的参数来使得代码执行不同逻辑实现不同功能,这样的优点就是执行想要的既定逻辑而不需要修改代码重新编译与打包.在 Golang 语言中也为我们提供了相应 ...

  3. GoLang中flag标签使用

    正如其他语言一样,在 linux 系统上通过传入不同的参数来使得代码执行不同逻辑实现不同功能,这样的优点就是执行想要的既定逻辑而不需要修改代码重新编译与打包.在 Golang 语言中也为我们提供了相应 ...

  4. Notification(二)——PendingIntent的flag导致数据同样的问题

    MainActivity例如以下: package cc.cu; import android.os.Bundle; import android.view.View; import android. ...

  5. 自定义控件:Flag标签

    效果图: 只有一个自定义textview.源码很简单,可以阅读下. GitHub

  6. 用alarmmanager 多次发送PendingIntent

    遇到如下问题 service中得一随机数 用alarmmanager 发送PendingIntent的时候,receiver收到的随机数不变. pendingintent传值经常获取到的值是第一次的值 ...

  7. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

  8. [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?

    情况是这样的,使用NotificationManager触发多个Notification: private Notification genreNotification(Context context ...

  9. Android控件之Notification

    Android通知就是让设备在屏幕最顶上那栏里面显示图标,当滑下通知栏之后可以看到列表状的通知选项,有些是"通知"类型的,有些是"正在运行"类型的," ...

随机推荐

  1. eclipse开发cocos2dx 3.2环境搭建之中的一个: Android C\C++环境搭建(ndk r9d)

    这几天有时间,琢磨一下cocos2dx.cocos2d家族事实上挺庞大的.也有cocos2d-android这样的能够直接用Java语言来开发的,可是cocos2d-android资料相对少一些.并且 ...

  2. PHP——简单的表单提交

    <body> <form name="" method="post" action="CHULI.php"> < ...

  3. netlink--内核态与用户态通信

    1. 什么是 Netlink 什么是Netlink?Netlink是linux提供的用于内核和用户态进程之间的通信方式.但是注意虽然Netlink主要用于用户空间和内核空间的通信,但是也能用于用户空间 ...

  4. SpringBoot配置使用jsp页面技术

    SpringBoot配置使用jsp页面技术 1.pom配置 package配置必须为war类型 添加依赖 <packaging>war</packaging> <depe ...

  5. tp 批量转码

    读取王正东成功,然后把乱码一条一条的改回来... 专门针对mssql数据库的!!!

  6. tf.nn.conv2d实现卷积的过程

    #coding=utf-8 import tensorflow as tf #case 2 input = tf.Variable(tf.round(10 * tf.random_normal([1, ...

  7. 敏捷软件开发实践-Sprint Retrospective Meeting(转)

    介绍: 在敏捷开发模式中,Sprint Retrospective Meeting 也是一个必不可少的环节,它通常发生在每个Sprint的结尾,其主要作用是对于当前的迭代周期做一个阶段性的总结,包括好 ...

  8. 解决spring boot中rest接口404,500等错误返回统一的json格式

    在开发rest接口时,我们往往会定义统一的返回格式,列如: { "status": true, "code": 200, "message" ...

  9. UESTC 1511(差分约束)

    题目链接:http://acm.uestc.edu.cn/problem.php?pid=1511 思路:我们可以等到这样的5个关系式: k=1:dsit[a]-dist[b]>=0&& ...

  10. iOS开发之-- textview 光标起始位置偏移

    使用textview的时候,会发生光标偏移的情况,其实是因为iOS7里导航栏,状态栏等有个边缘延伸的效果在. 把边缘延伸关掉就好了.代码如下 //取消iOS7的边缘延伸效果(例如导航栏,状态栏等等) ...