首页 > 解决方案 > 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" />

标签: javaandroid

解决方案


请在您的 PendingIntent 中使用此标志:

PendingIntent.FLAG_CANCEL_CURRENT

推荐阅读