# Crash when disconnecting from a channel

**URL:** <https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267>\
**Category:** Android\
**Tags:** android, uikit\
**Created:** [March 25, 2022, 2:12pm UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267 "2022-03-25T14:12:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jack](https://community.sendbird.com/u/jack)\
**Post date:** [March 25, 2022, 2:12pm UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/1 "2022-03-25T14:12:56Z")

</div>

- OS: Android
- UIKit version: 2.2.4

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

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [March 27, 2022, 11:28pm UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/2 "2022-03-27T23:28:49Z")

</div>

Hi, @jack

Did you implement `SendBirdUIKit.init()`?

---

<div class="post-metadata">

**Author:** ![jack](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jack](https://community.sendbird.com/u/jack)\
**Post date:** [March 28, 2022, 1:51am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/3 "2022-03-28T01:51:50Z")

</div>

Hi @Doo_Rim ,

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

---

<div class="post-metadata">

**Author:** ![jack](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jack](https://community.sendbird.com/u/jack)\
**Post date:** [March 28, 2022, 6:47am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/4 "2022-03-28T06:47:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yongjun\_Choi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/yongjun_choi/32/36_2.png) [@Yongjun\_Choi](https://community.sendbird.com/u/Yongjun_Choi)\
**Post date:** [March 28, 2022, 10:34am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/5 "2022-03-28T10:34:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jack](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jack](https://community.sendbird.com/u/jack)\
**Post date:** [March 28, 2022, 10:53am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/6 "2022-03-28T10:53:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jack](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jack](https://community.sendbird.com/u/jack)\
**Post date:** [March 29, 2022, 5:34am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/7 "2022-03-29T05:34:58Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [March 30, 2022, 12:23am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/8 "2022-03-30T00:23:20Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![jack](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jack](https://community.sendbird.com/u/jack)\
**Post date:** [March 30, 2022, 2:34am UTC](https://community.sendbird.com/t/crash-when-disconnecting-from-a-channel/4267/9 "2022-03-30T02:34:26Z")

</div>

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.

```auto
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!
