Live Audio Room Kit
  • iOS
  • Android : Java
  • Flutter
  • React Native
  • Overview
  • Quick start
  • Customize prebuilt features
    • Overview
    • Set avatar for users
    • Customize the seats
    • Customize the seat-taking logic
    • Customize the background
    • Customize user attributes
    • Set a leave confirmation dialog
    • Modify user interface text
    • Customize the bottom menu bar buttons
    • Customize the text message UI
  • Advanced features
    • Send virtual gifts
    • Use Tokens for authentication
  • API Reference
    • API
    • Event
  • Migration guide
    • Migrating to ZEGOCLOUD Maven
  • Documentation
  • Live Audio Room Kit
  • Customize prebuilt features
  • Set a leave confirmation dialog

Set a leave confirmation dialog

Last updated:2023-06-04 16:49

Live Audio Room Kit (ZegoUIKitPrebuiltLiveAudioRoom) ends a live audio room by default when the user clicks the Leave the room button or the Android’s Back button.

If you want to add a confirmation dialog box to double confirm whether the user wants to leave the live audio room, you can use the confirmDialogInfo config.

confirmDialogInfo: After configuring this parameter, ZegoUIKitPrebuiltLiveAudioRoom will pop up a confirmation dialog box with the default style before ending the live audio room, showing the confirmation info you set.

The following shows the effect and the reference code:

Java Kotlin
public class LiveAudioRoomActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call);

        addFragment();
    }

    public void addFragment() {
        long appID = yourAppID;
        String appSign = yourAppSign;
        String userID = yourUserID;
        String userName = yourUserName;

        boolean isHost = getIntent().getBooleanExtra("host", false);
        String roomID = getIntent().getStringExtra("roomID");

        ZegoUIKitPrebuiltLiveAudioRoomConfig config;
        if (isHost) {
            config = ZegoUIKitPrebuiltLiveAudioRoomConfig.host();
        } else {
            config = ZegoUIKitPrebuiltLiveAudioRoomConfig.audience();
        }

        ZegoDialogInfo confirmDialogInfo = new ZegoDialogInfo();
        confirmDialogInfo.title= "Leave the room";
        confirmDialogInfo.message= "Are you sure to leave the room?";
        confirmDialogInfo.cancelButtonName= "Cancel";
        confirmDialogInfo.confirmButtonName= "OK";
        config.confirmDialogInfo = confirmDialogInfo;

        ZegoUIKitPrebuiltLiveAudioRoomFragment fragment = ZegoUIKitPrebuiltLiveAudioRoomFragment.newInstance(appID, appSign, userID, userName,roomID,config);
        getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow();
    }
}
class LiveAudioRoomActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_live)
        addFragment()
    }

    private fun addFragment() {
        val appID: Long = yourAppID
        val appSign = yourAppSign
        val userID = YourUserID
        val userName = YourUserName

        val isHost = intent.getBooleanExtra("host", false)
        val roomID = intent.getStringExtra("roomID")

        val config: ZegoUIKitPrebuiltLiveAudioRoomConfig = if (isHost) {
            ZegoUIKitPrebuiltLiveAudioRoomConfig.host()
        } else {
            ZegoUIKitPrebuiltLiveAudioRoomConfig.audience()
        }

        val confirmDialogInfo = ZegoDialogInfo()
        confirmDialogInfo.title = "Leave the room"
        confirmDialogInfo.message = "Are you sure to leave the room?"
        confirmDialogInfo.cancelButtonName = "Cancel"
        confirmDialogInfo.confirmButtonName = "OK"
        config.confirmDialogInfo = confirmDialogInfo

        val fragment = ZegoUIKitPrebuiltLiveAudioRoomFragment.newInstance(appID, appSign, userID, userName, roomID, config)
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow()
    }
}
Page Directory