2014-09-23 83 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