Crash when disconnecting from a channel

  • OS: Android
  • UIKit version: 2.2.4

I’m implementing disconnection in ChannelList and Channel like below:

override fun onPause() {
    super.onPause()
    SendBirdUIKit.disconnect {  }
}

override fun onResume() {
    super.onResume()
    SendBirdUIKit.connect { }
}

It works in ChannelList while it crash the app when disconnecting from a channel. The exception is included like below:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.sendbird.android.User.getUserId()' on a null object reference
        at com.sendbird.uikit.utils.ChannelUtils.makeProfileUrlsFromChannel(ChannelUtils.java:115)
        at com.sendbird.uikit.utils.ChannelUtils.loadChannelCover(ChannelUtils.java:103)
        at com.sendbird.uikit.widgets.ChannelPreview.drawChannel(ChannelPreview.java:102)

What is the best practice to disconnect from a channel? Thanks!

Hi, @jack

Did you implement SendBirdUIKit.init()?

Hi @Doo_Rim ,

Thanks for the reply. I called SendBirdUIKit.init() in the class which extends Application.

I’ve also tried to call init() before connect() instead of calling it once in BaseApplication class. No luck tho.

@jack UIKit manages its own connection.
Please do not call connect or disconnect directly. (I think it’ll be easier.)

Thanks for the reply. However, we have to restrict the connection due to the limit of peak concurrent users. Is there any workaround to disconnect from a ChannelActivity without crashing the app?

@Yongjun_Choi @Doo_Rim Is there a handler observing user ID once init is succeeded? It seems like the app inevitably crashes no matter where I disconnect from the server.

Hi @jack I am sorry that I didn’t understand what you want to implement. If you refer to our sample. there are processes of sign in and sign out.

Hi @Doo_Rim ,

Thanks for your reply and sorry for the confusion. The goal is simple. We’re required to create a 1-on-1 channel using 2 user IDs. When the conversation is ended, we need to disconnect from the Sendbird server. The provided samples do have sign out process with ChannelListActivity. However, it does not include an entry to ChannelActivity in the HomeActivity.

For instance, we’re creating a channel like the following.

GroupChannel.createChannelWithUserIds(ids, true) { channel , e -> 
    val intent = ChannelActivity.newIntentFromCustomActivity(context, CustomChannelActivity.class, channel.url)
    startActivity(intent)
}

The only problem here is that the channel creation works well while it crash when we call SendBirdUIKit.disconnect after the ChannelActivity is finished. (The crash doesn’t occur when ChannelListActivity is finished - Just like how you sign out in the UIKit samples)

Thanks again!