Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 意图';s flags和PendingEvent.getBroadcast_Android_Android Intent - Fatal编程技术网

Android 意图';s flags和PendingEvent.getBroadcast

Android 意图';s flags和PendingEvent.getBroadcast,android,android-intent,Android,Android Intent,我在我的代码中得到此异常: ...IllegalArgumentException...Cant use FLAG_RECEIVER_BOOT_UPGRADE here... 查看android源代码似乎无法将标志设置为将通过以下方式触发的意图: PendingIntent.getBroadcast(...); 以下是Android源代码: ... if (type == INTENT_SENDER_BROADCAST) { if ((intent.getFlags()&In

我在我的代码中得到此异常:

...IllegalArgumentException...Cant use FLAG_RECEIVER_BOOT_UPGRADE here...
查看android源代码似乎无法将标志设置为将通过以下方式触发的意图:

PendingIntent.getBroadcast(...);
以下是Android源代码:

...
if (type == INTENT_SENDER_BROADCAST) {
    if ((intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
        throw new IllegalArgumentException("Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
    }
}
...
这是我的代码:

Intent myIntent = new Intent(context, MyReceiver.class);
//myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if i remove the comment it doesn't work
PendingIntent pending = PendingIntent.
          getBroadcast(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);

原因我不清楚,任何人都可以帮我澄清一下吗?

当您使用
getBroadcast()
获得一个
pendingent
时,此意图将被广播给广播接收者。它将不用于启动活动。因此,您无法设置任何与活动相关的标志。无论如何,在这种情况下,它们没有任何意义

为什么要设置
标记活动\u新任务
,以便广播?这毫无意义

Android使用意图有3个完全不同的目的:

  • 启动/与
    活动通信
  • 启动/与
    服务通信
  • 广播到
    BroadcastReceiver
  • pendingent
    类提供了3种不同的方法来获取用于这些不同目的的pendingent:

  • getActivity()
  • getService()
  • getBroadcast()
  • 您需要确保使用正确的方法达到正确的目的


    是的,您可以在PendingEvent中设置与活动相关的意图标志,只要调用getActivity()获取PendingEvent。

    当您使用
    getBroadcast()
    获取
    PendingEvent
    时,此意图将被广播给BroadcastReceivers。它将不用于启动活动。因此,您无法设置任何与活动相关的标志。无论如何,在这种情况下,它们没有任何意义

    为什么要设置
    标记活动\u新任务
    ,以便广播?这毫无意义

    Android使用意图有3个完全不同的目的:

  • 启动/与
    活动通信
  • 启动/与
    服务通信
  • 广播到
    BroadcastReceiver
  • pendingent
    类提供了3种不同的方法来获取用于这些不同目的的pendingent:

  • getActivity()
  • getService()
  • getBroadcast()
  • 您需要确保使用正确的方法达到正确的目的


    是的,只要调用getActivity()获取Pending帐篷,就可以在Pending帐篷中设置与活动相关的意图标志。

    嘿,大卫,这是我的错。当我遇到那个问题时,我没有给予足够的关注,谢谢你的回应。嘿,大卫,这是我的错。当时我遇到这个问题时没有给予足够的关注,不过谢谢你的回复。