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. HashedWheelTimer 原理

    HashedWheelTimer 是根据 Hashed and Hierarchical Timing Wheels: Data Structuresfor the Efficient Impleme ...

  2. ng-bind,ng-cloak优化数据显示

    <div>{{text}}</div> 当我们使用angular在页面中有取值的时候,如果出现网络加载慢的问题,可能会在页面上出现{{text}}这种不好的体验,那么angul ...

  3. 简述UICollectionView 使用

    一.介绍 UICollectionView类负责管理数据的有序集合以及以自定义布局的模式来呈现这些数据,它提供了一些常用的表格(table)功能,此外还增加了许多单栏布局.UICollectionVi ...

  4. 解决 label 多行间距

    使用. 一个是间距,一个是行高,但是鉴于多行,都写的话,就相当于双倍行高了.我就用行高代替间距. self.textLabel.attributedText = [self getAttributed ...

  5. SQlserver 行转列

    列转行编程中很容易碰到,小弟在此总结下, 行转列暂时还没遇到,遇到再补充. 列转行:  , , , ,  以上都是以逗号分隔,分隔符可以自定义.

  6. 20145225《Java程序设计》 第5周学习总结

    20145225<Java程序设计> 第5周学习总结 教材学习内容总结 第八章 异常处理 8.1语法与继承架构 try.catch:try.catch代表错误的对象后做一些处理. 异常继承 ...

  7. 1055: [HAOI2008]玩具取名

    Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用"WING" ...

  8. poj3264 - Balanced Lineup(RMQ_ST)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 45243   Accepted: 21240 ...

  9. Android--Content Provider

    1.内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整的机制,允许一个程序访问另一个程序中的数据,同时还能保证被访数据的安全性. 2.内容提 ...

  10. JSP标准标签库(JSTL)之核心标签(下)

      前面记录了核心标签的前几种,现在来接着记录. 七.<c:import>标签 使用<c:import>标签可以包含一个FTP服务器中不同的网页内容.语法格式: <c:i ...