In the Android build of my Flutter application, the app fails to properly process push notifications that are received while the app is not running. When the app is either running and visible, or running and backgrounded, push notifications are received and processed as expected.
The following error is thrown and displayed in the Flutter debugging console when a push notification is received by the unopened app:
E/AndroidRuntime(23160): java.lang.RuntimeException: Unable to create service com.backendless.backendless_sdk.common.FlutterBackendlessFCMService: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.backendless.BackendlessPrefs.getNotificationIdGeneratorInitValue()' on a null object reference
E/AndroidRuntime(23160): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4567)
E/AndroidRuntime(23160): at android.app.ActivityThread.access$1700(ActivityThread.java:256)
E/AndroidRuntime(23160): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2110)
E/AndroidRuntime(23160): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(23160): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(23160): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(23160): at android.app.ActivityThread.main(ActivityThread.java:7870)
E/AndroidRuntime(23160): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(23160): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(23160): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(23160): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.backendless.BackendlessPrefs.getNotificationIdGeneratorInitValue()' on a null object reference
E/AndroidRuntime(23160): at com.backendless.push.BackendlessFCMService.<init>(Unknown Source:15)
E/AndroidRuntime(23160): at com.backendless.backendless_sdk.common.FlutterBackendlessFCMService.<init>(Unknown Source:0)
E/AndroidRuntime(23160): at java.lang.Class.newInstance(Native Method)
E/AndroidRuntime(23160): at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
E/AndroidRuntime(23160): at androidx.core.app.CoreComponentFactory.instantiateService(Unknown Source:0)
E/AndroidRuntime(23160): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4536)
E/AndroidRuntime(23160): ... 9 more
It seems related to preference initialization/existence and I have experimented with the order of various initialization logic but have yet to come up with anything that resolves this issue.
The issue is pretty critical because the crash occurs during the processing of the notification, and so the notifications are never properly delivered/made visible to the app user.
I have just recently started working with the push notification functionality, again, because of the recent update to handle the Android SDK 31 messaging intent issue.
The issue seems related to an old issue that was resolved a few years ago:
NullPointerException in BackendlessFCMService when app is killed - Bug - Backendless Support
Backendless Version (3.x / 5.x, Online / Managed / Pro )
Online
Client SDK (REST / Android / Objective-C / Swift / JS )
Backendless Flutter SDK: 7.3.5
Application ID
D42DAAD0-460A-4D81-8C17-8A8EA5DCE101
Expected Behavior
Please describe the expected behavior of the issue, starting from the first action.
- Send a push notification template from the Backendless Console
- Push notification is handled while mobile app is closed
Actual Behavior
- Send a push notification template from the Backendless Console
- Processing of push notification crashes when app is closed