2014-09-23 84 views
8

Android文档描述了PendingIntentIntentSender两个类,但不清楚何时或为什么要使用IntentSender而不是PendingIntent - 事实上,大部分描述看起来对于两者都是相同的。何时使用IntentSender与PendingIntent?

PendingIntent文档:

一个Intent和目标操作的说明用它来执行。这个类的实例用(...)创建;返回的对象可以交给其他应用程序,以便他们可以执行您以后代表您所描述的操作。

IntentSender文档:

一个Intent和目标操作的说明用它来执行。返回的对象可以交给其他应用程序,以便他们可以执行您稍后代表您所描述的操作。

这两个类是Parcelable和两个类允许接收器与sendsendIntent或(具有几乎相同的签名),调用的动作。

由于您需要现有的PendingIntent来创建一个IntentSender,您会在什么情况下创建一个IntentSender而不是仅仅使用您的PendingIntent

+0

你有没有找到一个答案?我面临同样的问题,但这个问题的唯一答案并没有给出意义的解释。 – cerisier 2017-12-29 12:31:15

回答

-2

有很好的例子和解释here

这里是一个快速的总结:

IntentSender

甲IntentSender是不能被直接构造的IntentSenderandroid.content.IntentSender

实例的实例,但可以从android.app.PendingIntent实例与PendingIntent.getIntentSender()获得因为PendingIntent封装了一个IntentSender

IntentSender Documentation

的PendingIntent

一个PendingIntent是你给外国申请(如AlarmManagerAppWidgetManager),它允许外国申请使用应用程序的权限来执行预定义的一块令牌的代码。

基本上,收到PendingIntent的外国应用程序不知道被PendingIntent包装的Intent的内容,但是当满足条件条件时,外国应用程序应该将意图发送回主应用程序。

PendingIntent Documentation