# Listening to Events

As soon as you call `watchChannel` on a Channel or `queryChannels`, the SDK will start receiving events to stay up to date with changes. You can hook into specific events:

<tabs>

<tabs-item value="kotlin" label="Kotlin">

```kotlin
val chatClient = ChatClient.instance()
val channelClient = chatClient.channel("messaging", "general")

// Subscribe for new message events
val disposable: Disposable = channelClient.subscribeFor<NewMessageEvent> { newMessageEvent ->
    val message = newMessageEvent.message
}

// Dispose when you want to stop receiving events
disposable.dispose()
```

</tabs-item>

<tabs-item value="java" label="Java">

```java
ChatClient chatClient = ChatClient.instance();
ChannelClient channelClient = chatClient.channel("messaging", "general");

// Subscribe for new message events
Disposable disposable = channelClient.subscribeFor(
        new Class[]{NewMessageEvent.class},
        (ChatEvent event) -> {
            Message message = ((NewMessageEvent) event).getMessage();
        }
);

// Dispose when you want to stop receiving events
disposable.dispose();
```

</tabs-item>

</tabs>

As an example, let's see how you can close the chat screen when the currently logged-in user is removed from the channel. You need to subscribe for `NotificationRemovedFromChannelEvent` events which are triggered when a user is removed from the list of channel members. If the removed user matches the currently logged-in user, you should dismiss the screen.

<tabs>

<tabs-item value="kotlin" label="Kotlin">

```kotlin
class ChatFragment : Fragment() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // Setup chat screen components

        val chatClient = ChatClient.instance()
        val channelClient = chatClient.channel("messaging", "general")
        channelClient.subscribeFor<NotificationRemovedFromChannelEvent>(viewLifecycleOwner) { event ->
            val removedUserId = event.member.user.id
            val currentUserId = chatClient.getCurrentUser()?.id
            if (removedUserId == currentUserId) {
                // Close the current chat screen as the current user has been removed
                requireActivity().onBackPressedDispatcher.onBackPressed()
            }
        }
    }
}
```

</tabs-item>

<tabs-item value="java" label="Java">

```java
class ChatFragment extends Fragment {

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // Setup chat screen components

        ChatClient chatClient = ChatClient.instance();
        ChannelClient channelClient = chatClient.channel("messaging", "general");
        channelClient.subscribeFor(
                getViewLifecycleOwner(),
                new Class[]{NotificationRemovedFromChannelEvent.class},
                (ChatEvent event) -> {
                    Member member = ((NotificationRemovedFromChannelEvent) event).getMember();

                    String removedUserId = member.getUser().getId();
                    String currentUserId = chatClient.getCurrentUser().getId();
                    if (removedUserId.equals(currentUserId)) {
                        // Close the current chat screen as the current user has been removed
                        requireActivity().getOnBackPressedDispatcher().onBackPressed();
                    }
                }
        );
    }
}
```

</tabs-item>

</tabs>

In the example above, you navigate away from the Fragment by calling `OnBackPressedDispatcher::onBackPressed` when the event is received. Notice that you don't need to dispose the subscription manually since you pass `viewLifecycleOwner` (Kotlin) or `getViewLifecycleOwner()` (Java) as a parameter and the subscription is automatically canceled when the Fragment's view is destroyed.


---

This page was last updated at 2026-04-17T17:33:31.801Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/sdk/android/v6/client/guides/events/](https://getstream.io/chat/docs/sdk/android/v6/client/guides/events/).