android PengdingIntent Extras信息

keywords:android PengdingIntent intent Extras信息

發送通知時我們通常會在通知欄附加上一些信息,當通過通知啓動某個activity時,利用這些附加信息完成某些工作,但是會遇到這類問題:在通過通知啓動的activity無法獲取到intent的附加信息,或者是獲取的附加信息跟自己期望的不一致,不然你不間斷的發通知,每個通知附加信息不一樣。

n.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int) info.pId, intent,
						PendingIntent.FLAG_UPDATE_CURRENT);
藍色標記的切忌不能隨便弄個參數糊弄。看最後解釋。

之所以會犯這類錯大多人估計都被PendingIntent的getActivity的requestCode這個參數的註釋誤導了。雖然google說它暫時沒用,但是通過實踐和google後,發現這個參數很有用

解釋如下

Anroid reuses intents, the intent action and request code make it unique, but not the extra data. So you need to set a unique request id or use different intent actions. – Bachi Aug 15 '11 at 11:58


http://stackoverflow.com/questions/1198558/how-to-send-parameters-from-a-notification-click-to-an-activity

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章