Dev/delivery 85881/android delegate to singleton instance #433
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.
Fix: Plugin Instance Recreation on App Background/Foreground
Summary
This PR fixes an issue where a new
AppsflyerSdkPlugininstance was created when the app went to background (via back button) and returned to foreground. This caused loss of plugin state, callbacks, and potential issues with deep linking and conversion data.Problem
When the Android app goes to background using the back button and returns to foreground, Flutter's engine may be recreated, which causes Flutter to instantiate a new plugin instance. This resulted in:
Solution
Implemented a Delegate + Singleton pattern:
AppsflyerSdkPluginDelegate(new) - A lightweight delegate class that Flutter instantiates. It forwards all calls to the singleton implementation.AppsflyerSdkPlugin(modified) - Now a singleton that holds all plugin state and logic. Ensures the same instance is reused across engine recreations.PluginLogger(new) - Utility class for controlled debug logging via system property or programmatically.Changes
New Files
AppsflyerSdkPluginDelegate.java- Delegate entry point for Flutter plugin registrationPluginLogger.java- Debug logging utility with system property controlModified Files
AppsflyerSdkPlugin.java- Converted to singleton pattern, added extensive debug loggingpubspec.yaml- Updated AndroidpluginClasstoAppsflyerSdkPluginDelegateArchitecture
Debug Logging
Debug logging can be enabled in two ways:
1. Via ADB (requires app restart)
adb shell setprop debug.appsflyer.flutter true2. Automatically with SDK debug mode
When
isDebug: trueis passed toinitSdk(), plugin logging is automatically enabled.3. Programmatically
Log Output Examples
When enabled, logs show the singleton pattern working:
Testing
Checklist