【发布时间】:2020-06-05 12:51:12
【问题描述】:
场景
我定期从 FCM 接收数据通知。通知触发同步操作
问题
有时通知会突然出现,从而同时触发多个同步操作
解决方案
FirebaseMessagingService 的去抖动
public class MyFirebaseMessagingService extends FirebaseMessagingService {
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getData().containsKey("one_notification_key")){
// DEBOUNCE -> execute the code only once after some cooling period
}
}
}
问题:如何在这种情况下实现去抖动?
*请注意,我不想执行第一个而忽略其余的一段时间。我宁愿从跨越一段时间的一系列通知中执行最后一个
【问题讨论】:
标签: android firebase-cloud-messaging