PendingIntent的Flags的类型:

  1. * Flags的类型:
  2. FLAG_ONE_SHOT:得到的pi只能使用一次,第二次使用该pi时报错
  3. FLAG_NO_CREATE: 当pi不存在时,不创建,返回null
  4. FLAG_CANCEL_CURRENT: 每次都创建一个新的pi
  5. FLAG_UPDATE_CURRENT: 不存在时就创建,创建好了以后就一直用它,每次使用时都会更新pi的数据(使用较多)
  6. * 在AlarmManager中的使用
  7. Intent intent = new Intent("action", null, context, serviceClass);
  8. PendingIntent pi = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  9. AlarmManager manager = (AlarmManager)probe.getSystemService(Context.ALARM_SERVICE);
  10. manager.set(AlarmManager.RTC_WAKEUP, milis, pi);
  11. * 在NotificationManager中的使用
  12. Intent intent = new Intent();
  13. intent.setAction("myaction");
  14. PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  15. NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  16. Notification n = new Notification();
  17. n.icon = R.drawable.ic_launcher;
  18. n.when = System.currentTimeMillis();
  19. n.setLatestEventInfo(this,"this is title", "this is a message", pi);
  20. nm.notify(0, n);

* send()方法是用,调用PendingIntent.send()会启动包装的Intent(如启动service,activity)

* cancel()方法是为了解除PendingIntent和被包装的Intent之间的关联,此时如果再调用send()方法,则会抛出CanceledException异常

android: PendingIntent的使用的更多相关文章

  1. android PendingIntent 使用通知传递多个参数,及不覆盖的问题

    Intent updateIntent = new Intent(GetNoticeService.this, DetailGonggaoActivity.class); updateIntent.p ...

  2. Android PendingIntent小结

    官方文档的解释   A description of an Intent and target action to perform with it.   注意有一个target action,既Pen ...

  3. Android · PendingIntent学习

    Intent 是及时启动,intent 随所在的activity 消失而消失 PendingIntent用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转.   ...

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

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

  5. 【Android 界面效果24】Intent和PendingIntent的区别

    intent英文意思是意图,pending表示即将发生或来临的事情.  PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. In ...

  6. Android开发之PendingIntent的使用

    PendingIntent,待确定的意图,等待的意图 官网链接:http://developer.android.com/reference/android/app/PendingIntent.htm ...

  7. Android 4.2 通知通过PendingIntent启动Activity失败的问题

    今天突然发现在Android 4.2手机上点击通知消息无法打开Activity的问题,具体Logcat信息如下: 01-09 11:37:43.733: WARN/ActivityManager(92 ...

  8. Android中pendingIntent的深入理解

    pendingIntent字面意义:等待的,未决定的Intent.要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, i ...

  9. Android基础知识巩固:关于PendingIntent和广播

    平时使用广播的场合比较多,但细节的东西,看过了也没有总结,以至于某些场合有小问题,还是要把原理和属性搞清楚才能运用自如. 其实也是自己比较懒,先看别人的blog,有个概念再去官网看英文的能好理解一些. ...

随机推荐

  1. POJ2309 -- BST

    找找规律,实际上是二分查找的过程,只要找到了mid与输入的n相同的话,直接输出left和right就可以了. 代码如下: #include <iostream> using namespa ...

  2. 一个有趣的基于C++的模拟发牌程序

    在内存中模拟出一副牌,然后模拟洗牌,发牌等动作. 流程是这样的:构建一副牌保存到一个数组中—洗牌—创建玩家—向玩家发牌–输出每个玩家的牌. #include <stdio.h> #incl ...

  3. 按enter执行click或者搜索问题

    最近需要将按按钮搜索的功能,改为支持按enter回车键,搜索. 实现按enter,执行click事件还是比较简单的. //按回车搜索用户 $(window).keydown(function (eve ...

  4. 自动化运维工具之ansible(转)

    原文链接:http://os.51cto.com/art/201409/451927_all.htm

  5. LVM基本概念、管理

    一.传统磁盘管理的问题 当分区大小不够用时无法扩展其大小,只能通过添加磁盘.创建新的分区来扩充空间,但是新添加进来的硬盘是作为独立文件系统存在的,原有的文件系统并未得到扩充,上层应用很多时候只能访问一 ...

  6. SQLServer 脚本测试

    最近在做大数据同步的工作.很少数据需要特殊清洗算法,每次测试,都测试全部数据,浪费时间,可以只测试那些特殊数据即可(切记).

  7. 1016. Phone Bills (25)

    分析: 模拟题,提交无数次WA,注意几点: 1.如果某人没有有效通话记录,则不输出该人的信息,在此WA15次,题目看了N遍也没出现啊. 2.通话时间钱的计算:假设我们计算time1到time2的账单: ...

  8. 【树上莫队】【带修莫队】【权值分块】bzoj4129 Haruna’s Breakfast

    #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using ...

  9. spring 框架通过new Object()获取applicationContext 中的bean方案

    工作中,需要手动创建一个对象,但用到了spring容器中对象的业务逻辑,这时候就要去通过获取容器中的对象.这时候,可以通过实例化一个实现了ApplicationContextAware接口的类获取sp ...

  10. Mac上创建cocos2d-x工程

    1.自选版本-下载 http://www.cocos2d-x.org/download 2.解压(自选路径) 3.在cocos2d-x解压目录下新建 Projects 文件夹. 3.打开终端 4.进入 ...