简体   繁体   English

为什么我不能在PendingIntent中使用Intent.FLAG_ACTIVITY_NEW_TASK

[英]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 必须是以下一项或多项: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_INS ,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: PendingIntent.getActivity()getActivity()方法flags的最后一个参数只能具有以下int类型的标志:

FLAG_ONE_SHOT
FLAG_NO_CREATE
FLAG_CANCEL_CURRENT
FLAG_UPDATE_CURRENT
or any of the flags as supported by Intent.fillIn() which are: Intent.fillIn()支持的任何标志是:
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 . 因此,您不能在PendingIntent.getActivity()方法中使用Intent.FLAG_ACTIVITY_NEW_TASK ,因此必须在Intent中将其用作启动标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么同时使用Intent.FLAG_ACTIVITY_NEW_TASK和Intent.FLAG_ACTIVITY_SINGLE_TOP? - Why use both Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_SINGLE_TOP? 无法使用Intent。FLAG_ACTIVITY_NEW_TASK - Cannot Use Intent.FLAG_ACTIVITY_NEW_TASK 使用标志Intent.FLAG_ACTIVITY_NEW_TASK从onPostExecute()方法启动意图不起作用 - Starting intent from onPostExecute() method with a flag Intent.FLAG_ACTIVITY_NEW_TASK is not working Android:PendingIntent是Intent的一种形式,那么PendingIntent为什么不是Intent的子类呢? - Android: A PendingIntent is a form of an Intent, then why isn't PendingIntent a subclass of Intent? 替代Intent.FLAG_ACTIVITY_CLEAR_TASK - Alternative to Intent.FLAG_ACTIVITY_CLEAR_TASK 使用 Intent.createChooser 并出现错误:从 Activity 上下文外部调用 startActivity() 需要 FLAG_ACTIVITY_NEW_TASK 标志 - Using Intent.createChooser and getting error: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag 错误FLAG_ACTIVITY_NEW_TASK标志 - error FLAG_ACTIVITY_NEW_TASK flag 为什么图片可以返回到上一个活动但不打算返回新活动 - why Image can return to previous activity but not intent to new activity 处理FLAG_ACTIVITY_NEW_TASK的NewIntent - Handling onNewIntent for FLAG_ACTIVITY_NEW_TASK 上下文需要 FLAG_ACTIVITY_NEW_TASK 但我已经设置了那个标志 - Context wants FLAG_ACTIVITY_NEW_TASK but I've already set that flag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM