chat-sdk / chat-sdk-android

Chat SDK Android - Open Source Mobile Messenger
https://chatsdk.co
Other
1.61k stars 611 forks source link

Android: notification is not come (+ crash happened) when app process is killed #743

Open AliakseiZhukouski opened 1 year ago

AliakseiZhukouski commented 1 year ago
  1. Is the bug present in the demo Chat SDK project? dependencies are: sdk.chat:firebase-app:5.4.2" sdk.chat:pro-firebase-last-online:5.4.2"

  2. What modifications have you made to the Chat SDK?

  3. Android Version: Android 10 (API 29)

  4. Steps taken to reproduce the problem: 1) create thread 1 by 1 (using user firebase id) 2) user 1 being in foreground from UI (chat details) send message to thread 3) user 2 being in background (app process was intentionally killed by swiping up from recent) does not get any notification and from time to time get crash (in 50% of cases) - crash output is below

  5. Expected result: Application being in background (when process was killed swiping up from recents) should get notification

  6. Actual result: Application is not get any notification and sometimes can even crashes (being in background and killed as process). In the logcat output we can see the next crash 03-18 19:37:39.418 E/AndroidRuntime( 4883): java.lang.RuntimeException: Unable to start receiver sdk.chat.core.push.DefaultBroadcastReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'org.greenrobot.greendao.query.QueryBuilder sdk.chat.core.dao.DaoSession.queryBuilder(java.lang.Class)' on a null object reference 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.app.ActivityThread.handleReceiver(ActivityThread.java:4238) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.app.ActivityThread.access$1700(ActivityThread.java:274) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2113) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.os.Handler.dispatchMessage(Handler.java:107) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.os.Looper.loop(Looper.java:237) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.app.ActivityThread.main(ActivityThread.java:8167) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at java.lang.reflect.Method.invoke(Native Method) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 03-18 19:37:39.418 E/AndroidRuntime( 4883): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'org.greenrobot.greendao.query.QueryBuilder sdk.chat.core.dao.DaoSession.queryBuilder(java.lang.Class)' on a null object reference 03-18 19:37:39.418 E/AndroidRuntime( 4883): at sdk.chat.core.session.StorageManager.fetchEntityWithEntityID(StorageManager.java:162) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at sdk.chat.core.session.StorageManager.fetchThreadWithEntityID(StorageManager.java:209) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at sdk.chat.core.push.BaseBroadcastHandler.onReceive(BaseBroadcastHandler.java:34) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at sdk.chat.core.push.DefaultBroadcastReceiver.onReceive(DefaultBroadcastReceiver.java:18) 03-18 19:37:39.418 E/AndroidRuntime( 4883): at android.app.ActivityThread.handleReceiver(ActivityThread.java:4229) 03-18 19:37:39.418 E/AndroidRuntime( 4883): ... 8 more

  7. Comments:

bensmiley commented 1 year ago

I have investigated this and I'm not able to reproduce the issue. I would need a reliable way to reproduce it to go further.

shjman commented 1 year ago

you can try to add this

if (!ChatSDK.db().isDatabaseOpen) {
        val currentUserId = ChatSDK.auth().currentUserEntityID
        if (currentUserId != null) {
            try {
                ChatSDK.db().openDatabase(currentUserId)
            } catch (e: Exception) {
                Log.e...
            }
        }
    }
after a moment when you call ChatSDK.builder()... .activate(context)