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. windows 2008 server ftp 无法访问解决办法

    安装一个WINDOWS自带的FTP服务器,整了接近一天的时间,按网上的教程,无论如何搭建.最终都是内部IP可以访问.外部IP无法访问. 1.防火墙全部关掉. 2.FTP所在目录给的是EVERYONE的 ...

  2. 缺jstl.jar包导致的代码出现异常

    java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config 看报错中的红色部分,意思是缺类异常,再看后面蓝色粗体倾斜部分, ...

  3. OA项目之分页

    using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Digit ...

  4. mormot json操作

    使用JSon只需要引用一个文件synCommons. procedure TForm1.Button1Click(Sender: TObject);var jo: Variant; i: Int64; ...

  5. rm: Argument list too long

    rm -rf  /testdir/* -bash: /bin/rm: Argument list too long 解决: cd /testdir/; ls | xargs rm -rf

  6. nginx 报错 upstream timed out (110: Connection timed out)解决方案

    nginx 作PHP的web接口服务器. 在线上发现时不时经常崩溃.504,导致接口访问无响应回复. 查看日志: [error] 11618#0: *324911 upstream timed out ...

  7. 专题:『Channel Bonding/team』——EXPERIMANTAL!!!

    Linux内核支持的多网卡聚合方法——bond.team bond 优点:经过长时间的实践检验,具有较高的稳定性:kernel-2.4及以上内核均广泛支持 缺点:需要通过sysfs或发行版定制的网卡配 ...

  8. 理解浏览器的重绘与回流(repaint&&reflow)

    今天在做练习的时候,遇到了重绘与回流这个词,表示连个毛都没有听过.遂查之,首先将网上的(http://blog.sina.com.cn/s/blog_8dace7290102wezv.html)关于这 ...

  9. 在centos上编译安装mariadb数据库

    一.安装前提(准备数据文件.安装其他依赖的软件) 1.准备数据存放的目录 [root@localhost ~]# fdisk /dev/sdb  (fdisk /dev/sdb 创建一个逻辑分区/de ...

  10. linux中实现自动交互的3中方法

    本文参考了 http://os.51cto.com/art/200912/167898.htm 有些命令例如ftp需要交互,有三种方法可以实现. 方法一(重定向)简单直观,也经常有实际应用,但是在自动 ...