Set a leave confirmation dialog
Live Streaming Kit (ZegoUIkitPrebuiltLiveStreaming) ends a live by default when the user clicks the End Live 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 a live, you can use the confirmDialogInfo
config: After configuring the confirmDialogInfo parameter, ZegoUIKitPrebuilt will pop up a confirmation dialog box with the default style before ending the live, showing the confirmation info you set.
The effect will be like this:

Here is the reference code:
public class LiveActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_live);
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
String liveID = "testLiveID";
// Modify your custom configurations here.
ZegoUIKitPrebuiltLiveStreamingConfig config;
if (isHost) {
config = ZegoUIKitPrebuiltLiveStreamingConfig.host();
} else {
config = ZegoUIKitPrebuiltLiveStreamingConfig.audience();
}
ZegoDialogInfo confirmDialogInfo = new ZegoDialogInfo();
confirmDialogInfo.title= "Leave confirm";
confirmDialogInfo.message= "Do you want to leave?";
confirmDialogInfo.cancelButtonName= "Cancel";
confirmDialogInfo.confirmButtonName= "Confirm";
config.confirmDialogInfo = confirmDialogInfo;
ZegoUIKitPrebuiltLiveStreamingFragment fragment = ZegoUIKitPrebuiltLiveStreamingFragment
.newInstance(appID, appSign, userID, userName, liveID, config);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow();
}
}
If you want to listen for leave events, ZegoUIKitPrebuiltLiveStreaming provides a setOnLeaveLiveStreamingListener
method, the leaveLiveStreamingListener
will be triggered when the live ends. And sure, you can also implement custom business logic in the leaveLiveStreamingListener
.