推送通知欄 PendingIntent 參數解讀

PendingIntent android.app.PendingIntent.getActivity(Context context,int requestCode,Intent intent,int flags)

源碼註釋:

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use theIntent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

  • Parameters:

  • context The Context in which this PendingIntent should start the activity.

  • requestCode Private request code for the sender (currently not used).

  • intent Intent of the activity to be launched.

  • flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.

  • Returns:

  • Returns an existing or new PendingIntent matching the given parameters. May return null only ifFLAG_NO_CREATE has been supplied.

    flags:

(1) android.app.PendingIntent.FLAG_UPDATE_CURRENT

如果PendingIntent已經存在,保留它並且只替換它的extra數據。

(2) android.app.PendingIntent.FLAG_CANCEL_CURRENT

如果PendingIntent已經存在,那麼當前的PendingIntent會取消掉,然後產生一個新的PendingIntent。

(3) android.app.PendingIntent.FLAG_ONE_SHOT

PendingIntent只能使用一次。調用了實例方法send()之後,它會被自動cancel掉,再次調用send()方法將失敗。

(4) android.app.PendingIntent.FLAG_NO_CREATE

如果PendingIntent不存在,簡單了當返回null。

requestCode:

如果一次推送幾個通知到通知欄,且requestCode一致的話,PendingIntent裏裏邊的數據會被最後一個推送過來的替換掉,即:第一個推送的數據會跟第二個一樣。這點一定要注意。

微信公衆賬號資源的連接

歡迎關注公衆賬號 jszj2014215 分享android資訊和技術相關問題

http://mp.weixin.qq.com/s?__biz=MzA3NzMxODEyMQ==&mid=224348184&idx=1&sn=67b5c05163a3cc182b8e9061dde815a1#rd


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