diff --git a/src/pages/docs/chat/getting-started/android.mdx b/src/pages/docs/chat/getting-started/android.mdx index 7a63016ceb..f1d69004a5 100644 --- a/src/pages/docs/chat/getting-started/android.mdx +++ b/src/pages/docs/chat/getting-started/android.mdx @@ -161,6 +161,19 @@ fun ConnectionStatusUi(connection: Connection) { ``` + + Update the `App` component to display the connection status using the new `ConnectionStatusUi` component: @@ -237,6 +250,11 @@ The above code creates a room with the ID `my-first-room` and sets up a listener Monitoring the room status is useful for deciding when to show a loading spinner or other UI elements while waiting for the room to be created or joined. + + ## Step 4: Send a message Messages are how your clients interact with one another. @@ -957,6 +975,34 @@ class MainActivity : ComponentActivity() { ``` +### Room lifecycle management + +When managing room lifecycles in your application, keep these best practices in mind: + + + +**Room state transitions** + +Understanding room state transitions helps you build robust chat applications: + +* `Initialized` → A temporary state for room when it is first initialized. +* `Initialized` → `Attaching` → `Attached`: Normal room attachment flow using `room.attach`. +* `Attached` → `Detaching` → `Detached`: Muting or pausing a room functionality using `room.detach`, so it won't receive any events. +* `Detached` → `Attaching` → `Attached`: Resuming a muted room using `room.attach`, make sure to fetch missed messages using [history api](/docs/chat/rooms/history?lang=kotlin). +* `Attached` → `Releasing` → `Released`: Room is detached removing all local resources using `rooms.release` and is garbage collected. +* `Attached` → `Suspended`: Temporary underlying network disconnection, connection keeps reconnecting every 2 minutes (default is 2 mins). +* `Suspended` → `Attached`: Automatic reconnection after network recovery, make sure to fetch missed messages using [history api](/docs/chat/rooms/history?lang=kotlin). +* `Failed` → Represents underlying connection is in `Failed` state. + +Use these transitions to provide appropriate UI feedback, such as showing loading indicators during `Attaching` or `Detaching` states, or displaying "Connection lost" messages during `Suspended` state. + ## Next steps Continue to explore the documentation with Kotlin as the selected language: