java - Android Notification Click to Broadcast Receiver 获得相同的意图字符串
问题描述
我有一个在通知点击时触发的广播接收器。我正在传递一个字符串以通知广播接收器。字符串的值每次都不同,但是当我测试我的应用程序时,我只能看到我第一次单击通知时收到的值。现在,尽管传递了新值,但我从通知到广播接收器的每个值都是相同的。
我的代码:
//Creating notification
Intent snoozeIntent = new Intent(getApplicationContext(), ServiceLauncherBroadcast.class);
snoozeIntent.putExtra("order_id", orderId);
//In the broadcast receiver
startWorkManager(intent.getStringExtra("order_id")
//Manifest
<receiver android:name = ".utils.ServiceLauncherBroadcast" />
解决方案
请在您的 PendingIntent 中使用此标志:
PendingIntent.FLAG_CANCEL_CURRENT
推荐阅读
- sql - BigQuery:存储半结构化 JSON 数据
- python - 未找到“联系人”的反向。'contact' 不是有效的视图函数或模式名称
- c - 主线程上的条件变量块
- php - 在 Laravel 中安装插件失败
- python - 在 Tensorflow mnist 教程中显示预测图像的问题
- ruby-on-rails - 工作结束后,工作人员中的内存未释放
- java - 如何使用 Java 将 XML 文档转换为目标 XML 模板结构(减少属性/元素)
- r - 按日期范围设置不平衡面板数据
- android - 向广播接收器发送隐式意图
- android - 解决。在 AlertDialog 中显示 MapView 时,对话框按钮消失