天天看點

推送通知欄 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 the

Intent.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 if

    FLAG_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裡裡邊的資料會被最後一個推送過來的替換掉,即:第一個推送的資料會跟第二個一樣。這點一定要注意。

微信公衆賬号資源的連接配接

繼續閱讀