Init AppsFlyer SDK after coming from a background push notification on Android device causes a NullPointerException
Describe the bug Init causes NullPointerException after entering the app from a push notification.
To Reproduce Steps to reproduce the behavior:
- Use Firebase messaging for sending a push notification in the background process when the app is terminated
- Click on notification to enter the app
- Init AppsFlyer SDK
- See error:
E/MethodChannel#af-api: Failed to handle method call
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
at com.appsflyer.AppsFlyerLibCore.start(:921)
at com.appsflyer.AppsFlyerLibCore.start(:902)
at com.appsflyer.AppsFlyerLibCore.start(:897)
at com.appsflyer.appsflyersdk.AppsflyerSdkPlugin.initSdk(AppsflyerSdkPlugin.java:586)
at com.appsflyer.appsflyersdk.AppsflyerSdkPlugin.onMethodCall(AppsflyerSdkPlugin.java:128)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:197)
at android.app.ActivityThread.main(ActivityThread.java:8016)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Expected behavior No error.
Smartphone (please complete the following information):
- Device: Xiaomi Mi 10T Pro 5G
- OS: Android 11 (API 30)
Additional context: Same problem as this closed issue: https://github.com/AppsFlyerSDK/appsflyer-flutter-plugin/issues/109 If the app is in the background, but not terminated, there is no error as the SDK has already been initialized.
I'm also receiving a lot of error reports regarding this bug. Looking forward to a fix.
Same issue
plugin fix for this issue was released on v6.11.3