From 4973d93e9ec53d9ea77485c3d141a0d915305d3b Mon Sep 17 00:00:00 2001 From: lehcar09 Date: Wed, 4 Dec 2024 23:08:12 +0800 Subject: [PATCH] Add try catch block for possible race condition when unregistering the ConnectivityChangeReceiver --- .../main/java/com/google/firebase/messaging/SyncTask.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/firebase-messaging/src/main/java/com/google/firebase/messaging/SyncTask.java b/firebase-messaging/src/main/java/com/google/firebase/messaging/SyncTask.java index c0c4074c11e..9787eb2fd08 100644 --- a/firebase-messaging/src/main/java/com/google/firebase/messaging/SyncTask.java +++ b/firebase-messaging/src/main/java/com/google/firebase/messaging/SyncTask.java @@ -191,7 +191,11 @@ public void onReceive(Context context, Intent intent) { Log.d(TAG, "Connectivity changed. Starting background sync."); } task.firebaseMessaging.enqueueTaskWithDelaySeconds(task, 0); - task.getContext().unregisterReceiver(this); + try { + task.getContext().unregisterReceiver(this); + } catch (IllegalArgumentException e) { + // The receiver is not registered + } task = null; } }