Intent和Pending Intent之間有什麼區別。基本上我知道Intent,它在startActivity(intent),startService(intent)調用時使用,也用在putExtra()中。可以使用Pending Intent。請澄清。解釋Intent和PendingIntent之間的區別
回答
Pending intent
是意圖,將在稍後開始。
Normal intent
被傳遞給startActivity(意向)或StartService(意向)時,開始的時候
一個的PendingIntent是你給到另一個應用程序令牌(例如通知,告警管理或其他第三方應用程序),它允許這個其他應用程序使用您的應用程序的權限來執行預定義的一段代碼。
要通過掛起的意圖執行廣播,請通過PendingIntent.getBroadcast()獲取PendingIntent。
要通過未決意圖執行活動,您需要通過PendingIntent.getActivity()接收活動。
A PendingIntent
是Activity
,Broadcast
或Service
。
爲什麼要用PendingIntent
?
因爲,例如,如果你想創建一個Bluetooth Intent
,你讓這樣的:
Intent myIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(myIntent);
你不會讓Bluetooth
權限是:android.permission.BLUETOOTH_ADMIN
,所以你必須創建一個PendingIntent
與此同時,您不需要獲得新的Intent
的許可。
換句話說:這允許外部應用程序使用您的應用程序的權限來執行預定義的代碼片段。
這是一個令牌,你給另一個應用程序(例如NotificationManager,AlarmManager或第三個應用程序)。
你可以開始一個新的活動:getActivity(Context context, int requestCode, Intent intent, int flags)
執行廣播:getBroadcast(Context context, int requestCode, Intent intent, int flags)
或啓動服務:getService(Context context, int requestCode, Intent intent, int flags)
"Note that the activity will be started outside of the context of an existing
activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the
Intent."
您可以創建新PendingIntent
,或者使用現有的與flags
,看到這個答案:https://stackoverflow.com/a/15298131/2668136
看到這些教程更多的信息:
1. Simple Launch Activity with PendingIntent
2. Alarm Service using AlarmManager
3. Android Notifications using NotificationManager
4. Using AlarmManager and BroadcastReceiver
後兩者都非常簡單和偉大。
希望這是有益的,更容易理解。
- 1. 和intent和setcontentview之間的區別
- 2. Android:VideoView和Intent之間的區別.ACTION_VIEW
- 3. onetomany和manytomany註釋之間的區別
- 4. 地標和註釋之間的區別
- 5. 解釋和編譯Haskell之間的ncurses的區別?
- 6. Page'loaded'事件行爲的解釋 - navigateTo()和goBack()之間的區別
- 7. 解釋計劃和執行計劃之間的區別
- 8. Java:流和I/O流之間的區別解釋
- 9. 解釋drawable,drawable-ldpi,drawable-mdpi和drawable-hdpi之間的區別
- 10. 你能解釋* ptr ++和*(++ ptr)之間的區別嗎?
- 11. Spring MVC:請解釋@RequestParam和@ModelAttribute之間的區別
- 12. Java解釋器和JVM之間的區別
- 13. 你能解釋StrictMock和Partialmock之間的區別嗎?
- 14. 解釋ActionController#respond_to和ActionController之間的區別:: respond_to
- 15. 如何解釋「import my_module」和「from my_module import my_str」之間的區別?
- 16. 你能解釋一下AIDL和Service之間的區別嗎?
- 17. 有人可以解釋Java AudioFormat和AudioFileFormat之間的區別嗎?
- 18. 請解釋函數($變量)和函數()之間的區別
- 19. 瞭解ToArray和JSON之間的區別
- 20. 瞭解.body和body之間的區別
- 21. Hibernate - 註釋和公共註釋之間的區別?
- 22. JPA級聯註釋和Hibernate級聯註釋之間的區別
- 23. 之間的〜/和的區別../
- 24. '#','%'和'$'之間的區別
- 25. {!!之間的區別!!}和{{}}
- 26. '+ ='和'= +'之間的區別?
- 27. 「。+」和「。+?」之間的區別
- 28. .eq之間的區別。和==
- 29. #。/和#之間的區別。 ./
- 30. !=和!之間的區別==
看到這個:http://stackoverflow.com/a/4812421/2668136和這一個:http:// stackoverflow。com/a/15873786/2668136 – Fllo
沒問題但你可以用例子來解釋,上面的鏈接關於意圖和意圖的意圖之間的權限差異說了請在使用許可的例子說明。 –