简体   繁体   English

无法使用Intent。FLAG_ACTIVITY_NEW_TASK

[英]Cannot Use Intent.FLAG_ACTIVITY_NEW_TASK

I have an alarm project, on AlarmReceiver I have this code. 我有一个警报项目,在AlarmReceiver有此代码。

the error is the flag is cannot be used, Android Studio say FLAG_ACTIVITY_NEW_TASK is not listed in usable Intent Flag. 错误是无法使用该标志,Android Studio说FLAG_ACTIVITY_NEW_TASK未在可用的Intent标志中列出。

how to fix that? 如何解决?

http://i.stack.imgur.com/vbpLs.png http://i.stack.imgur.com/vbpLs.png

Try this : 尝试这个 :

Intent myIntent = new Intent(context, DoSomething.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Then in your PendingIntent 然后在您的PendingIntent

 PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, myIntent, 0);

You put the flag in the wrong place. 您将标志放置在错误的位置。 Where you put it only flags for PendingIntent creation go. 您仅在其中放置创建PendingIntent的标志。

You need to do this instead: 您需要这样做:

myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Note (from the documentation ): PendingIntent flags 注意(来自文档 ):PendingIntent标志

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. 可以是FLAG_ONE_SHOT,FLAG_NO_CREATE,FLAG_CANCEL_CURRENT,FLAG_UPDATE_CURRENT或Intent.fillIn()支持的任何标志,以控制实际发送发生时可以提供的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? 为什么我不能在PendingIntent中使用Intent.FLAG_ACTIVITY_NEW_TASK - Why can't I use Intent.FLAG_ACTIVITY_NEW_TASK in PendingIntent 使用标志Intent.FLAG_ACTIVITY_NEW_TASK从onPostExecute()方法启动意图不起作用 - Starting intent from onPostExecute() method with a flag Intent.FLAG_ACTIVITY_NEW_TASK is not working 替代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 处理FLAG_ACTIVITY_NEW_TASK的NewIntent - Handling onNewIntent for FLAG_ACTIVITY_NEW_TASK Android FLAG_ACTIVITY_NEW_TASK无效 - Android FLAG_ACTIVITY_NEW_TASK not working 关于上下文FLAG_ACTIVITY_NEW_TASK的错误 - error about context FLAG_ACTIVITY_NEW_TASK 解析活动上下文需要FLAG_ACTIVITY_NEW_TASK标志。 这真的是您想要的吗? - Resolve Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM