[英]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.