fix: Android prevent crash when cleaning up uninitialized SDK on destroy #1871
+18
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fix reported crashes when handlers / observers are removed on destroy and the SDK is uninitialized or cleaned up already.
Details
To address #1554
removeHandlers()andremoveObservers()calls in try-catch blocks withinonHostDestroy()andonCatalystInstanceDestroy()to handle cases where the native OneSignal SDK throws "Must call 'initWithContext' before use" during activity destruction.oneSignalInitDoneflag further down past the nativeOneSignal.initWithContext(context, appId)call. The native SDK already handles if initWithContext is called while it is still initializing.Motivation
Bug fix, fix crash
Scope
When activity being destroyed
Testing
Manual testing
Manually ran app in Android 35 emulator, app initializes, gets IAMs, get notifications.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is