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. }

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();

代码解释
     
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. Intent简介

    1 Intent概念 1.1 Intent的作用 指明Intent所要启动的对象 提供将要启动对象组件运行需要的数据 组件类型 启动方法 Activity startActivity(Intent i ...

  5. Android开发之PendingIntent的使用

    PendingIntent,待确定的意图,等待的意图 官网链接:http://developer.android.com/reference/android/app/PendingIntent.htm ...

  6. AlarmManager与PendingIntent

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

  7. Android中pendingIntent的深入理解

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

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

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

  9. widget intent重复问题

    今天在做android widget时发现点击任意widget时只会更新最后一个widget 原来是requestCode的问题 Intent intent = new Intent(WidgetPr ...

随机推荐

  1. poj 3111 卖珠宝问题 最大化平均值

    题意:有N件分别价值v重量w的珠宝,希望保留k件使得 s=v的和/w的和最大 思路:找到贡献最大的 设当前的s为mid(x) 那么贡献就是 v-w*x 排序 ,取前k个 bool operator&l ...

  2. 使用perl发邮件

    如果你使用的是 window 系统,没有 sendmail 工具.这时你就可以使用 perl 的 MIME:Lite 模块作为邮件客户端来发送邮件. 这里我们直接用 cpan 来安装(需要 root ...

  3. MySQL 5.7远程连接

    将/etc/mysql/my.cnf中的bind_address那一行注释掉或修改为"bind_address=0.0.0.0": bind_address并没有在/etc/mys ...

  4. Android 游标

    静下心来,学一下Android的数据库连接. 1.直接从getReadableDatabase()与getWritableDatabase()入手.    --getReadableDatabase( ...

  5. 3,Flask 中的模板语言 Jinja2 及 render_template 的深度用法

    Flask中默认的模板语言是Jinja2 现在我们来一步一步的学习一下 Jinja2 捎带手把 render_template 中留下的疑问解决一下 首先我们要在后端定义几个字符串,用于传递到前端 S ...

  6. sql查询作业答案

    sql查询作业答案   阅读目录 一 题目 二 答案 一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成 ...

  7. JAVA中使用AES加密解密

    技术交流群: 233513714 /** * AES加密测试 * * @param str 加密参数 */ public void aesTest(String str) { log.info(&qu ...

  8. 《Cracking the Coding Interview》——第13章:C和C++——题目4

    2014-04-25 19:50 题目:深拷贝和浅拷贝有什么区别?如何应用? 解法:深拷贝传值,浅拷贝传引用.java里对此做了限制,而C++里面用起来更自由.大结构不宜传值,因为拷贝过程效率低. 代 ...

  9. shell脚本批量下载资源并保留路径

    示例资源列表 如url.txt: http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png http://su.bdimg.co ...

  10. 24、php知识点总结基础教程--part-2

    1.表单处理 ①post请求 <html> <body> <form action="welcome.php" method="post&q ...