首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

【转】PendingIntent跟Intent的区别

2012-09-29 
【转】PendingIntent和Intent的区别String msg 你好,美女String number 135****6784SmsManager sms

【转】PendingIntent和Intent的区别

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

2)代码解释
      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在进行被赋予的相关的操作。

原文地址 http://wayfarer.iteye.com/blog/586159

热点排行