NullPointerException in BackendlessFCMService when app is killed

Backendless Versin: 5.2.2
Andoid Version: 8.0.0

I can receive my push notifications as expected, if the app is running or in background. But when I kill the app, the notifications do not appear. In the logs I have found a NullPointerException thrown in the BackendlessFCMService:

java.lang.RuntimeException: Unable to instantiate service com.kewitschka.lovr.messaging.PushMessageService: java.lang.NullPointerException: Attempt to invoke interface method 'int android.content.SharedPreferences.getInt(java.lang.String, int)' on a null object reference
        at android.app.ActivityThread.handleCreateService(ActivityThread.java)
        at android.app.ActivityThread.access$1800(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
        at android.os.Handler.dispatchMessage(Handler.java)
        at android.os.Looper.loop(Looper.java)
        at android.app.ActivityThread.main(ActivityThread.java)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
     Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int android.content.SharedPreferences.getInt(java.lang.String, int)' on a null object reference
        at com.backendless.AndroidBackendlessPrefs.getNotificationIdGeneratorInitValue(Unknown Source)
        at com.backendless.Backendless.getNotificationIdGeneratorInitValue(Unknown Source)
        at com.backendless.push.BackendlessFCMService.<init>(Unknown Source)
        at com.kewitschka.lovr.messaging.PushMessageService.<init>(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.Class.newInstance(Class.java)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java) 
        at android.app.ActivityThread.access$1800(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java) 
        at android.os.Handler.dispatchMessage(Handler.java) 
        at android.os.Looper.loop(Looper.java) 
        at android.app.ActivityThread.main(ActivityThread.java) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) 

manifest.xml

<service android:name=".messaging.PushMessageService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
</service>

PushMessageService.java

public class PushMessageService extends BackendlessFCMService {

@Override
public boolean onMessage(Context context, Intent intent) {
    //some logic
}}

build.gradle

...
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'

Hi.
Could you clarify, what do you mean when your are talking that you make “kill”.

I managed to reproduce your issue, and i created the inner task [BKNDLSS-18043] to investigate the problem deeper.

Hi, Kevin. We’ve fixed the problem.
You may try new sdk from here: https://github.com/Backendless/Android-SDK/releases/tag/5.2.3.
While it is not in the maven repository yet. I think it will be published in a one day.

1 Like

Hi Oleg,

great! Thank you very much.