Android开发之PendingIntent的使用
PendingIntent,待确定的意图,等待的意图
官网链接:http://developer.android.com/reference/android/app/PendingIntent.html

官网关于该类的继承关系,PendingIntent继承自Object。因为该类为final,所以没有子类,无法被继承。
要想得到一个PendindIntent对象,需要使用方法类的静态方法 getActivity(Context, int, Intent, int),getActivities(Context, int, Intent[], int),getBroadcast(Context, int, Intent, int),getService(Context, int, Intent, int)
这几个静态方法分别对应着Intent的行为,跳转到Activity,Activities,Broadcast,Service。
这4个静态方法的参数都一样,其中第一个和第三个参数比较的重要,其次是第二个和第四个。第一个参数传入当前的context,第三个参数传入intent.
PendingIntent是一个特殊的Intent,主要区别是intent是立马执行,PendingIntent是待确定的Intent。PendingIntent的操作实际上是传入的intent的操作。
使用pendingIntent的目的主要是用于所包含的intent执行是否满足某些条件。
主要的地方:Notification,SmsManager,AlarmManager等
1.Notification例子:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
mBuilder.setSmallIcon(R.drawable.notification_icon)
mBuilder.setContentTitle("My notification")
mBuilder.setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this,0,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
2.SmsManager例子:
SmsManager smsManage = SmsManager.getDefault();
Intent intent=new Intent("SEND_SMS_ACTION");
PendingIntent pendingIntent=PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
smsManage.sendTextMessage("13xxxxxxxxx", null, "这是一条短信", pendingIntent, null);
主要常量
FLAG_CANCEL_CURRENT:如果当前系统中已经存在一个相同的PendingIntent对象,那么就将先将已有的PendingIntent取消,然后重新生成一个PendingIntent对象。
FLAG_NO_CREATE:如果当前系统中不存在相同的PendingIntent对象,系统将不会创建该PendingIntent对象而是直接返回null。
FLAG_ONE_SHOT:该PendingIntent只作用一次。在该PendingIntent对象通过send()方法触发过后,PendingIntent将自动调用cancel()进行销毁,那么如果你再调用send()方法的话,系统将会返回一个SendIntentException。
FLAG_UPDATE_CURRENT:如果系统中有一个和你描述的PendingIntent对等的PendingInent,那么系统将使用该PendingIntent对象,但是会使用新的Intent来更新之前PendingIntent中的Intent对象数据,例如更新Intent中的Extras。
请参考:http://blog.csdn.net/hudashi/article/details/7060837
Android开发之PendingIntent的使用的更多相关文章
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序 在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity ...
- Android开发之Java集合类性能分析
对于Android开发者来说深入了解Java的集合类很有必要主要是从Collection和Map接口衍生出来的,目前主要提供了List.Set和 Map这三大类的集合,今天Android吧(ard8. ...
- Android开发之InstanceState详解
Android开发之InstanceState详解 本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...
- Android开发之Git配置
Android开发之Git配置 1.首先git配置: 输入命令: git config --global user.name "xxx.xx" git config --globa ...
- 【Android UI】Android开发之View的几种布局方式及实践
引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...
- Android开发之旅: Intents和Intent Filters(理论部分)
引言 大部分移动设备平台上的应用程序都运行在他们自己的沙盒中.他们彼此之间互相隔离,并且严格限制应用程序与硬件和原始组件之间的交互. 我们知道交流是多么的重要,作为一个孤岛没有交流的东西,一定毫无意义 ...
- Android开发之ViewPager+ActionBar+Fragment实现响应式可滑动Tab
今天我们要实现的这个效果呢,在Android的应用中十分地常见,我们可以看到下面两张图,无论是系统内置的联系人应用,还是AnyView的阅读器应用,我们总能找到这样的影子,当我们滑动屏幕时,Tab可 ...
- Android开发之Java必备基础
Android开发之Java必备基础 Java类型系统 Java语言基础数据类型有两种:对象和基本类型(Primitives).Java通过强制使用静态类型来确保类型安全,要求每个变量在使用之前必须先 ...
- Android开发之PopupWindow
/* * Android开发之PopupWindow * * Created on: 2011-8-8 * Author: blueeagle * Email: liujiaxiang@g ...
随机推荐
- ios错误修改了系统头文件
一.打开终端 二.进入Xcode 输入命令: cd /Users/apple/Library/Developer/Xcode/ 三.打开当前 输入命令: open . 四.将DerivedData ...
- OC1_银行账户类
// // BankAccount.h // OC1_银行账户类 // // Created by zhangxueming on 15/6/10. // Copyright (c) 2015年 zh ...
- Eclipse修改java代码后自动重启Tomcat解决办法
今天甚是郁闷,项目马上要上线了,早上刚到公司打开MyEclipse 10.07提示过期提示,这对于用惯了破解软件的帝国用户的我原本以为小菜一碟. 于是到网上到处找破解软件,不用多长时间,Ok 破解成功 ...
- iOS 多态的简单思想
/** * 多态:多种形态,是对于对象而言的,如果没有继承就没有多态 * * 在代码中体现:就是通过定义父类指针指向子类的对象 * * 好处:在函数或者方法的参数中如果传入的是父类指针,那么实现的时候 ...
- Java write And read Demo
以下代码主要实现java中的读文件 和写入文件,练习一下流操作. 要点: 1.读取文件时,一定要加编码格式,否则中文乱码 import java.io.BufferedReader;import ja ...
- 【安装操作系统】VMware 中安装 Redhat 5
引言 已有一台 Windows XP 家用机,安装 Linux 虚拟机,一不小心就会走弯路,因此本文提供一些入门级的经验来帮助你躲开歧途. 欢迎来到 lovickie 的博客 http://www.c ...
- 支持HTML5新标签
IE8/IE7/IE6支持通过document.createElement方法产生的标签, 可以利用这一特性让这些浏览器支持HTML5新标签, ...
- 对WebClient扩展自动解压缩页面
WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题. public class MyWebClient : WebClient { protected override WebR ...
- C# 多线程基础
多线程 无论您是为具有单个处理器的计算机还是为具有多个处理器的计算机进行开发,您都希望应用程序为用户提供最好的响应性能,即使应用程序当前正在完成其 他工作.要使应用程序能够快速响应用户操作,同时在用户 ...
- Javascript代码摘录
判断浏览器窗口高度 if (document.documentElement.clientHeight <800) { var elm = document.getElementById('Di ...