This guide builds a single chat window — no sidebar, no conversation list. Users go directly into a one-to-one or group chat. Good for support chat, dating apps, or notification-driven flows.This assumes you’ve already completed Integration (project created, dependencies installed, init + login working, theme set up).
Message header — displays user/group name, avatar, and status
Message list — real-time chat history with scrolling
Message composer — text input with media and attachments
The user or group ID is passed via Intent extras when launching the Activity — ideal for launching from a user profile, support button, or notification.
Update your MainActivity (or any other Activity) to launch MessageActivity with the appropriate user or group ID:
Passing Data via IntentYou can pass either:
uid (String) - for one-to-one chats
guid (String) - for group chats
The MessageActivity will automatically detect which type of chat to display based on the Intent extras.
Kotlin
Java
MainActivity.kt
import android.content.Intentimport android.os.Bundleimport android.util.Logimport androidx.activity.ComponentActivityimport androidx.activity.enableEdgeToEdgeimport com.cometchat.chat.core.CometChatimport com.cometchat.chat.exceptions.CometChatExceptionimport com.cometchat.chat.models.Userimport com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKitimport com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettingsclass MainActivity : ComponentActivity() { private val TAG = "MainActivity" private val appID = "APP_ID" // Replace with your App ID private val region = "REGION" // Replace with your App Region private val authKey = "AUTH_KEY" // Replace with your Auth Key or leave blank if you are authenticating using Auth Token private val uid = "cometchat-uid-1" // Replace with the UID of the user you want to chat with private val target_uid = "cometchat-uid-2" // Replace with the UID of the user you want to chat with private val uiKitSettings = UIKitSettings.UIKitSettingsBuilder() .setRegion(region) .setAppId(appID) .setAuthKey(authKey) .subscribePresenceForAllUsers() .build() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() CometChatUIKit.init(this, uiKitSettings, object : CometChat.CallbackListener<String?>() { override fun onSuccess(successString: String?) { Log.d(TAG, "Initialization completed successfully") loginUser() } override fun onError(e: CometChatException?) {} }) } private fun loginUser() { CometChatUIKit.login(uid, object : CometChat.CallbackListener<User>() { override fun onSuccess(user: User) { // Launch One-to-One or Group Chat Screen val intent = Intent(this@MainActivity, MessageActivity::class.java) intent.putExtra("uid", target_uid) // Pass the UID of the user you want to chat with startActivity(intent) } override fun onError(e: CometChatException) { // Handle login failure (e.g. show error message or retry) Log.e("Login", "Login failed: ${e.message}") } }) }}
MainActivity.java
import android.content.Intent;import android.os.Bundle;import android.util.Log;import androidx.activity.ComponentActivity;import com.cometchat.chat.core.CometChat;import com.cometchat.chat.exceptions.CometChatException;import com.cometchat.chat.models.User;import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;public class MainActivity extends ComponentActivity { private static final String TAG = "MainActivity"; private final String appID = "APP_ID"; // Replace with your App ID private final String region = "REGION"; // Replace with your App Region private final String authKey = "AUTH_KEY"; // Replace with your Auth Key private final String uid = "cometchat-uid-1"; // Replace with the UID of the user you want to chat with private final String target_uid = "cometchat-uid-2"; // Replace with the UID of the user you want to chat with @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setDecorFitsSystemWindows(false); // Equivalent to enableEdgeToEdge() UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder() .setRegion(region) .setAppId(appID) .setAuthKey(authKey) .subscribePresenceForAllUsers() .build(); CometChatUIKit.init(this, uiKitSettings, new CometChat.CallbackListener<String>() { @Override public void onSuccess(String success) { Log.d(TAG, "Initialization completed successfully"); loginUser(); } @Override public void onError(CometChatException e) { Log.e(TAG, "Initialization failed: " + (e != null ? e.getMessage() : "Unknown error")); } }); } private void loginUser() { CometChatUIKit.login(uid, new CometChat.CallbackListener<User>() { @Override public void onSuccess(User user) { Log.d(TAG, "Login successful for user: " + user.getUid()); // Launch One-to-One or Group Chat Screen Intent intent = new Intent(MainActivity.this, MessageActivity.class); intent.putExtra("uid", target_uid); startActivity(intent); } @Override public void onError(CometChatException e) { Log.e("Login", "Login failed: " + (e != null ? e.getMessage() : "Unknown error")); } }); }}