intent英文意思是意图,pending表示即将发生或来临的事情。 PendingIntent这个类用于处理即将发生的事情。比如在通知Notification中用于跳转页面,但不是马上跳转。
Intent 是及时启动,intent 随所在的activity 消失而消失。 PendingIntent 可以看作是对intent的包装,通常通过getActivity,getBroadcast ,getService来得到pendingintent的实例,当前activity并不能马上启动它所包含的intent,而是在外部执行 pendingintent时,调用intent的。正由于pendingintent中 保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行pendingintent里的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。另外还可以处理intent执行后的操作。常和alermanger 和notificationmanager一起使用。 Intent一般是用作Activity、Sercvice、BroadcastReceiver之间传递数据,而Pendingintent,一般用在 Notification上,可以理解为延迟执行的intent,PendingIntent是对Intent一个包装。

  1. private void showNotify(){
  2. Notification notice=new Notification();
  3. notice.icon=R.drawable.icon;
  4. notice.tickerText="您有一条新的信息";
  5. notice.defaults=Notification.DEFAULT_SOUND;
  6. notice.when=10L;
  7. // 100 毫秒延迟后,震动 250 毫秒,暂停 100 毫秒后,再震动 500 毫秒
  8. //notice.vibrate = new long[] { 100, 250, 100, 500 };出错?
  9. //notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, null, 0));
  10. notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, new Intent(this,Activity2.class), 0));//即将跳转页面,还没跳转
  11. NotificationManager manager=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE);
  12. manager.notify(0,notice);
  13. }
  1. private void showNotify(){
  2. Notification notice=new Notification();
  3. notice.icon=R.drawable.icon;
  4. notice.tickerText="您有一条新的信息";
  5. notice.defaults=Notification.DEFAULT_SOUND;
  6. notice.when=10L;
  7. // 100 毫秒延迟后,震动 250 毫秒,暂停 100 毫秒后,再震动 500 毫秒
  8. //notice.vibrate = new long[] { 100, 250, 100, 500 };出错?
  9. //notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, null, 0));
  10. notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, new Intent(this,Activity2.class), 0));//即将跳转页面,还没跳转
  11. NotificationManager manager=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE);
  12. manager.notify(0,notice);
  13. }
private void showNotify(){
Notification notice=new Notification();
notice.icon=R.drawable.icon;
notice.tickerText="您有一条新的信息";
notice.defaults=Notification.DEFAULT_SOUND;
notice.when=10L;
// 100 毫秒延迟后,震动 250 毫秒,暂停 100 毫秒后,再震动 500 毫秒
//notice.vibrate = new long[] { 100, 250, 100, 500 };出错?
//notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, null, 0));
notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, new Intent(this,Activity2.class), 0));//即将跳转页面,还没跳转
NotificationManager manager=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE);
manager.notify(0,notice);
}

1. GSM网络中android发送短信示例

  1. String msg ="你好,美女";
  2. String number = "135****6784";
  3. SmsManager sms = SmsManager.getDefault();
  4. PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(...),0);
  5. sms.sendTextMessage(number, null, msg, pi, null);
  6. Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();
  1. String msg ="你好,美女";
  2. String number = "135****6784";
  3. SmsManager sms = SmsManager.getDefault();
  4. PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(...),0);
  5. sms.sendTextMessage(number, null, msg, pi, null);
  6. Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();
String msg ="你好,美女";
String number = "135****6784";
SmsManager sms = SmsManager.getDefault(); PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(...),0);
sms.sendTextMessage(number, null, msg, pi, null);
Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();

代码解释       PendingIntent就是一个Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的别的时间做你安排做的事情 (By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself,就相当于PendingIntent代表了Intent)。本例中别的程序就是发送短信的程序,短信发送成功后要把intent广播出去 。       函数SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)中参数解释:       1)PendingIntent sentIntent:当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,否则产生错误代码并通过android.app.PendingIntent.OnFinished进行回调,这个参数最好不为空,否则会存在资源浪费的潜在问题;       2)PendingIntent deliveryIntent:是当消息已经传递给收信人后所进行的PendingIntent广播。       查看PendingIntent 类可以看到许多的Send函数,就是PendingIntent在进行被赋予的相关的操作。

[转]Intent和PendingIntent的区别的更多相关文章

  1. 【Android 界面效果24】Intent和PendingIntent的区别

    intent英文意思是意图,pending表示即将发生或来临的事情.  PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. In ...

  2. Intent和PendingIntent的区别

    intent英文意思是意图,pending表示即将发生或来临的事情.  PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转.  I ...

  3. 转:Intent与PendingIntent

    intent英文意思是意图,pending表示即将发生或来临的事情. PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. Int ...

  4. AlarmManager与PendingIntent

    1.AlarmManager的作用与PendingIntent的关系 顾名思义,就是“提醒”,是Android中常用的一种系统级别的提示服务,在特定的时刻为我们广播一个指定的Intent.简单的说就是 ...

  5. Android中pendingIntent的深入理解

    pendingIntent字面意义:等待的,未决定的Intent.要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, i ...

  6. Android基础知识巩固:关于PendingIntent和广播

    平时使用广播的场合比较多,但细节的东西,看过了也没有总结,以至于某些场合有小问题,还是要把原理和属性搞清楚才能运用自如. 其实也是自己比较懒,先看别人的blog,有个概念再去官网看英文的能好理解一些. ...

  7. Android之PendingIntent的深入理解

    PendingIntent字面意义:等待的,未决定的Intent.要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, i ...

  8. Intent讲解

    什么是Intent? Intent是一个消息传递对象,可以使用它来启动其它应用组件.Intent使组件之间通信更加便利,主要用于以下三点: 启动Activity: 可以将intent作为参数调用Con ...

  9. notification的使用

    示例: NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); No ...

随机推荐

  1. 【Tomcat】tomcat设置http文件下载,配置文件下载目录

    tomcat作为http的下载服务器,网上有很多办法 但我认为最简单的是:(亲测有效) 1.直接把文件放在 /var/lib/tomcat6/webapps/ROOT 目录下, 2.然后在网址中访问: ...

  2. gpk-update-icon占用CPU及清除【原创】

    发现服务器有个gpk-update-icon一直占用CPU进程 网上查看相关信息比较少. gpk-update-icon是gnome的更新图标进程 俩种处理方法: 1.杀掉gpk-update-ico ...

  3. 安装 Xamarin for Visual Studio

    总得来说,Xamarin 有“联网自动安装”和“手动安装”两种方式. 说明:本文涉及得资源链接都是官网的,同时,在 我的网盘 也有相关备份. 现在,我就以 Windows 为例来大概说明……(-=-我 ...

  4. salt-api起不来:ImportError('No module named wsgiserver2',)

    问题:启动salt-api时没有报错但是没有端口,查看/var/log/salt/api发现如下报错: 解决方法: 下载wsgiserver2文件,放到/usr/lib64/python2.7/sit ...

  5. Lynx以纯文本的形式下载网页

    Lynx是一款基于命令行的web浏览器 [root@test88 ~]# yum install lynx -y [root@test88 ~]# lynx www.baidu.com 以纯文本的形式 ...

  6. Geoserver WFS跨域设置

    测试版本为geoserver2.11.0. 两种方法都可以实现跨域设置: 第一种: 下载跨域jar包jetty-servlets.jar(下载geoserver使用的对应jetty版本——可以查看&l ...

  7. 深度学习方法(十二):卷积神经网络结构变化——Spatial Transformer Networks

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.机器学习技术感兴趣的同学加入. 今天具体介绍一个Google ...

  8. MVC – 9.mvc整体请求流程

    1.请求管道 2~5微软自己的验证,我们一般不用. 在全局配置文件中-已经配置一个路由过滤器-为第7个事件注册了路由方法 1.在application_start中向静态路由表注册了路由数据,在管道第 ...

  9. thinkphp5 返回数组提示variable type error: array

    浏览器访问控制器函数,而函数返回的是数组: function timeArr(){ $time = array(); for($i=1;$i<=7;$i++){ $d= date('d',Tim ...

  10. 使用minikube在windows构建kubernetes群集

    只建议在开发环境中使用,不建议在windows下使用docker或者kubernetes. 1. 安装VirtualBox或者Hyper-v(安装步骤略) 2. 下载kubectl和minikube工 ...