简体   繁体   中英

Why can't I use Intent.FLAG_ACTIVITY_NEW_TASK in PendingIntent

I am creating an app that will send a notification. However when I use this line of code:

PendingIntent pendingIntent = 
PendingIntent.getActivity(getApplicationContext(), 0, intent, 
Intent.FLAG_ACTIVITY_NEW_TASK);

It says:

Must be one or more of: PendingIntent.FLAG_ONE_SHOT, PendingIntent.FLAG_NO_CREATE, PendingIntent.FLAG_CANCEL_CURRENT, PendingIntent.FLAG_UPDATE_CURRENT, Intent.FILL_IN_ACTION, Intent.FILL_IN_DATA, Intent.FILL_IN_CATEGORIES, Intent.FILL_IN_COMPONENT, Intent.FILL_IN_PACKAGE, Intent.FILL_IN_SOURCE_BOUNDS, Intent.FILL_IN_SELECTOR, Intent.FILL_IN_CLIP_DATA

Can anyone tell me why this is happening and maybe suggest a way to fix it?

Thanks in advance.

If you look at the Documentation | PendingIntent.getActivity() , the last parameter in getActivity() method flags can have only following flags of int type:

FLAG_ONE_SHOT
FLAG_NO_CREATE
FLAG_CANCEL_CURRENT
FLAG_UPDATE_CURRENT
or any of the flags as supported by Intent.fillIn() which are:
FILL_IN_ACTION
FILL_IN_DATA
FILL_IN_CATEGORIES
FILL_IN_PACKAGE
FILL_IN_COMPONENT
FILL_IN_SOURCE_BOUNDS
FILL_IN_SELECTOR
FILL_IN_CLIP_DATA

Hence, you can't use Intent.FLAG_ACTIVITY_NEW_TASK in your PendingIntent.getActivity() method, so you must use this as a launch flag in your Intent .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM