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. iOS.ReactNative-4-react-native-command-line-tool

    Command line tool: react-native 1. react-native 是一个命令行工具 1.1 react-native简介 运行以下命令: ls -lt `which re ...

  2. Jmeter应用初步介绍

    一.工具介绍 Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试,但后来扩展到其他测试领域. 它可以用于测试静态和动态资 ...

  3. [Office][C#] NPOI、OpenXML SDK、OpenOffice.org SDK 写入资料到 EXCEL 档案[转]

    原文地址:http://www.dotblogs.com.tw/chou/archive/2010/04/29/14912.aspx 一.簡介 要將資料寫入 EXCEL 檔案有許多的方法,但假如電腦不 ...

  4. 安装 composer SSL operation failed with code 1

    gavin@webdev:~> curl -sS https://getcomposer.org/installer | php Downloading... Download failed: ...

  5. UICollectionView高级实践

    上一篇中的干货看完,不觉感觉还是有点虚,今天我们来点实的,做了两个小DEMO,源码已放GitHub,主要是针对UICollectionView做了联系.第一个DEMO是瀑布流的一个练习:第二个DEMO ...

  6. pycharm Cannot find declaration to goto----解决方案

    系统中已经有了该类库,还是找不到类提示 close the project in intellij. close intellij. go to the project folder and dele ...

  7. 20145225唐振远 《Java程序设计》第1周学习总结——小试牛刀

    20145225唐振远<Java程序设计>第1周学习总结——小试牛刀 教材学习内容总结 1.java语言概述:一门高级编程语言. 2.java语言的三种技术构架:java SE.java ...

  8. Android入门

    在学Android,摘自<第一行代码——Android> 布局管理 通过xml文件进行布局管理. android:id="@+id/button_1" 为当前的元素定义 ...

  9. NSDate--日期格式

    日期格式: 年: y 将年份 (0-9) 显示为不带前导零的数字 yy 以带前导零的两位数字格式显示年份 yyy 以四位数字格式显示年份 yyyy 以四位数字格式显示年份 月: M 将月份显示为不带前 ...

  10. Java入门1dayCode

    public class HelloWorld { /* * 多行注释方式 * main()方法: java语言的入口方法(函数) */ public static void main(String[ ...