Skip to content

Commit f5c0ced

Browse files
committed
Remove a few warnings and ensure to destroy the isolate when the FcmService is done
1 parent 97fe5fc commit f5c0ced

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

packages/firebase_messaging/android/src/main/java/io/flutter/plugins/firebasemessaging/FlutterFirebaseMessagingService.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,25 @@ public void onCreate() {
8484
}
8585
}
8686

87+
@Override
88+
public void onDestroy() {
89+
super.onDestroy();
90+
91+
if (isIsolateRunning.getAndSet(false)) {
92+
backgroundChannel = null;
93+
94+
backgroundFlutterView.destroy();
95+
backgroundFlutterView = null;
96+
}
97+
}
98+
8799
/**
88100
* Called when message is received.
89101
*
90102
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
91103
*/
92104
@Override
93-
public void onMessageReceived(final RemoteMessage remoteMessage) {
105+
public void onMessageReceived(@NonNull final RemoteMessage remoteMessage) {
94106
// If application is running in the foreground use local broadcast to handle message.
95107
// Otherwise use the background isolate to handle message.
96108
if (isApplicationForeground(this)) {
@@ -129,7 +141,7 @@ public void run() {
129141
* the same as the one retrieved by getInstanceId().
130142
*/
131143
@Override
132-
public void onNewToken(String token) {
144+
public void onNewToken(@NonNull String token) {
133145
Intent intent = new Intent(ACTION_TOKEN);
134146
intent.putExtra(EXTRA_TOKEN, token);
135147
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
@@ -215,7 +227,7 @@ public static void onInitialized() {
215227
*
216228
* @param channel Background method channel.
217229
*/
218-
public static void setBackgroundChannel(MethodChannel channel) {
230+
public static void setBackgroundChannel(@NonNull MethodChannel channel) {
219231
backgroundChannel = channel;
220232
}
221233

@@ -300,9 +312,8 @@ private static void executeDartCallbackInBackgroundIsolate(
300312
}
301313
args.put("handle", backgroundMessageHandle);
302314

303-
if (remoteMessage.getData() != null) {
304-
messageData.put("data", remoteMessage.getData());
305-
}
315+
messageData.put("data", remoteMessage.getData());
316+
306317
if (remoteMessage.getNotification() != null) {
307318
messageData.put("notification", remoteMessage.getNotification());
308319
}

0 commit comments

Comments
 (0)