The correct code is as follows:
Pendingintent contentintent = pendingintent.getactivity (testaty. this, 0, intent, pendingintent.flag_update_current);
MyCode
The previous error code is as follows:
Pendingintent contentintent = pendingintent.getactivity (testaty. this, 0, intent, 0);
MyCode
The last one is flag, be sure to set up, otherwise it will not successfully pass extras.
Here is the document description for flag:
public static final int flag_cancel_current
SINCE:API Level 1
Flag for use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
and getService(Context, int, Intent, int)
: If the described pendingintent already exists, the current one is canceled BEFO Re generating a new one. Retrieve a new pendingintent if you have only changing the extra data in the Intent; By canceling the previous pending intent, this ensures is only entities given the new data would be able to launch it. If This assurance was not a issue, consider FLAG_UPDATE_CURRENT
.
Constant value:268435456 (0x10000000)
public static final int flag_no_create
SINCE:API Level 1
Flag for use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
and getService(Context, int, Intent, int)
: If the described pendingintent does not already exist, then simply return null Instead of creating it.
Constant value:536870912 (0x20000000)
public static final int flag_one_shot
SINCE:API Level 1
Flag for use getActivity(Context, int, Intent, int)
with, getBroadcast(Context, int, Intent, int)
and getService(Context, int, Intent, int)
: This pendingintent can is only used once. If set, after send()
are called on it, it'll be automatically canceled for you and any future attempt to send through it w Ill fail.
Constant value:1073741824 (0x40000000)
public static final int flag_update_current
SINCE:API Level 3
Flag for use with getActivity(Context, int, Intent, int)
, getBroadcast(Context, int, Intent, int)
and getService(Context, int, Intent, int)
: If the described pendingintent already exists, then keep it, it's replace its Extra data with what are in this new Intent. This can is used if you is creating intents where only the extras is change, and don ' t care which any entities that received Your previous pendingintent'll be a able to launch it with your new extras even if they is not explicitly given to it.
Constant value:134217728 (0x08000000)
The extras value problem of pendingintent in notification.