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 ...
随机推荐
- StrHelper
public class StrHelper { private static string passWord; //加密字符串 /// <summary> /// 判断输入是否数字 // ...
- Apache配置多个监听端口
以前做PC上的,都是配置一个端口,整一大堆的虚拟目录: 在 \conf\extra下找到httpd-vhosts.conf这个配置文件,想下面这样配置就行,监听80端口,访问相应的ServerName ...
- os.walk获取同级目录具有随机性
1.在不同机器上,相同内容的目录和文件,os.walk获取结果中路径的先后顺序具有随机性. 2.查看os.walk源码得知,listdir具有随机性. 3.修改该源码,对listdir结果排序后,使得 ...
- 配置Apache+Mysql+Php
以下操作均在Debian 6.0 64bit 环境root权限下进行,如果提示权限不足请切换至root用户或者sudo,本人比较喜欢自行安装,因为安装的过程中能最小化安装而且能够知道安装了什么,然后可 ...
- 代C语言上机实践
这已经是开学第十二周了,个人感觉严老师教的这批学生效果不是很好,有的竟然毫不知道main函数前边的 int是做什么的.只知按照书本上给的样例程序一个字一个字的敲到编译器中,然后点击运行.有错误也不知道 ...
- win7win8远程桌面提示凭证不工作问题
今天在远程桌面win7的服务器时,突然发现win8.1系统总是无法连接成功,提示“你的凭证不工作”,但可以连接windows server 2008的服务器,找了其他人用win7的连接也是出现这个问题 ...
- 我对TCP CDG拥塞控制算法的改进和优化
其实这不是我的优化,我是借用了BBR之力. 借了什么力呢?这是我一再强调的,BBR最大的共享不是为Linux贡献了一个TCP拥塞控制算法(它同时在也BSD上被实现...),而是它重构了 ...
- Aspose.Cells.dll引用导入导出Excel
Aspose.Cells 导入导出EXCEL 文章出处:http://hi.baidu.com/leilongbing/item/c11467e1819e5417595dd8c1 修改样式 ...
- 《C和指针》读书笔记——第一章 快速上手
1.注释代码可以用: #if 0 statements #endif 2.参数被声明为const,表明函数将不会修改函数调用者的所传递的这个参数. 3.scanf("%d",&am ...
- 【加密】C#.NET 各种加密解密
包括:AES/DES/Base64/RSA/MD5/SHA256 http://www.sosuo8.com/article/show.asp?id=3083 http://blog.csdn.net ...