首页 \ 问答 \ 使用唯一的requestCode取消PendingIntent(Cancelling a PendingIntent with unique requestCode)

使用唯一的requestCode取消PendingIntent(Cancelling a PendingIntent with unique requestCode)

我在取消pendingintent时遇到了麻烦。 现在我像这样创建我的待定意图:

Intent intent = new Intent(_self, NotificationService.class); PendingIntent pi = PendingIntent.getService(this, task.getID, intent, 0);

task.getID在这里是一个唯一的int。 稍后在我的应用程序中,用户可以编辑“任务”,并可以决定取消通知(pendingintent)。 我试着像这样取消pendingintent:

Intent intent = new Intent(_self, NotificationService.class); PendingIntent pIntent = PendingIntent.getBroadcast(_self, task.getID, intent , PendingIntent.FLAG_NO_CREATE);
pIntent.cancel();

但它不起作用! 通知仍然显示。 在这种情况下,task.getID引用之前创建的唯一ID。

我尝试了几个不同的参数,PendingIntent.FLAG_NO_CREATE返回null,FLAG_UPDATE_CURRENT不起作用,FLAG_CANCEL_CURRENT也没有。 有人可以帮我这个,看看我做错了什么?


I'm having trouble with cancelling my pendingintent. Right now I create my pending intent like so:

Intent intent = new Intent(_self, NotificationService.class); PendingIntent pi = PendingIntent.getService(this, task.getID, intent, 0);

task.getID is a unique int here. Later on in my app a user can edit a "task" and can decide to cancel the notifications (pendingintent). I try to cancel the pendingintent like so:

Intent intent = new Intent(_self, NotificationService.class); PendingIntent pIntent = PendingIntent.getBroadcast(_self, task.getID, intent , PendingIntent.FLAG_NO_CREATE);
pIntent.cancel();

But it doens't work! The notifications still shows up. In this case, task.getID refers to the unique id that was created before.

I've tried several different parameters, PendingIntent.FLAG_NO_CREATE returns null, FLAG_UPDATE_CURRENT doens't work and FLAG_CANCEL_CURRENT neither. Can somebody please help me with this and see what it is I am doing wrong?


原文:https://stackoverflow.com/questions/19459765
更新时间:2023-09-27 18:09

最满意答案

eval不是必需的,但您的代码也不起作用。 它不是有效的Ruby代码。 它应该是

map.each do |old, new|
  task(old) do
    warn "[DEPRECATED] `#{old}' is deprecated. Use `#{new}' instead."
    find_and_execute_task(new)
  end
end

eval is not necessary, but your code will not work either. It is not valid Ruby code. It should be

map.each do |old, new|
  task(old) do
    warn "[DEPRECATED] `#{old}' is deprecated. Use `#{new}' instead."
    find_and_execute_task(new)
  end
end

相关问答

更多
  • 嗯,它看起来足够安全。 但是使用eval还有其他问题,例如难以调试代码,以及其他一些问题。 如果您在代码中生成此类自定义数据,我想可以枚举各种此类自定义项。 如果是这样,我会将代码保留在脚本中并保存在Drive just data中,并使用指针(如函数变体名称)来说明如何在脚本中重建配置对象。 例如: function buildConfig(data) { var config = JSON.parse(data); //only data, no code config.getInfo = th ...
  • https://github.com/douglascrockford/JSON-js JSON.parse(text, reviver) https://github.com/douglascrockford/JSON-js JSON.parse(text, reviver)
  • eval不是必需的,但您的代码也不起作用。 它不是有效的Ruby代码。 它应该是 map.each do |old, new| task(old) do warn "[DEPRECATED] `#{old}' is deprecated. Use `#{new}' instead." find_and_execute_task(new) end end eval is not necessary, but your code will not work either. It is ...
  • 您可以使用$GLOBALS[$interface]来获取数据。 但是,假设始终定义$_POST和$_GET ,您可以检查是否已定义键以获取它并取消设置,以避免出现警告。 public function fetch(string $method, ?string $request = null) { $interface = $this->interface_get($method); #$interface = '_POST'; if ($request === null) { ...
  • 这取决于你如何逃脱“数据”。 您的数据已找到 在" -delimited JavaScript字符串中 在' -delimited JavaScript字符串中 可能在HTML