Skip to content

Commit aaa03d8

Browse files
authored
fix: [SDK-4722] guard getNotifications() in onDetachedFromEngine (#1149) (#1150)
1 parent 7a6874c commit aaa03d8

2 files changed

Lines changed: 6 additions & 60 deletions

File tree

.github/pull_request_template.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

android/src/main/java/com/onesignal/flutter/OneSignalNotifications.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ public void onNotificationPermissionChange(boolean permission) {
228228
}
229229

230230
void onDetachedFromEngine() {
231+
// The Flutter engine can be torn down before OneSignal.initialize() has been
232+
// called from Dart (cold start, fast finish, etc.). Calling getNotifications()
233+
// in that state throws IllegalStateException from the native SDK. See #1149.
234+
if (!OneSignal.isInitialized()) {
235+
return;
236+
}
231237
// Unsubscribe so clicks while the engine is dead get queued by the native SDK
232238
// instead of dispatched on a detached channel.
233239
OneSignal.getNotifications().removeClickListener(this);

0 commit comments

Comments
 (0)