OnDisconnectedFromRoom () is called when the invited player leaves the game

I created a real-time multiplayer game with two other players (both are directly invited). This is how I did it:

Player Select Intent Created

Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, MAX_PLAYERS);
startActivityForResult(intent, REQ_GOOGLE_INVITE);


The onActivityResult()

following is done:

private void onPlayersInvited(Intent data) {
    // get the invitee list
    final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

    Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1, 5, 0);

    // create the activeRoom and specify a variant if appropriate
    RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
    RoomConfig roomConfig = roomConfigBuilder.build();
    Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);

    // prevent screen from sleeping during handshake

private RoomConfig.Builder makeBasicRoomConfigBuilder() {
    return RoomConfig.builder(this).setMessageReceivedListener(this).setRoomStatusUpdateListener(this).setSocketCommunicationEnabled(true)


My game starts on all three devices, but when I disconnect from the game on one invited device, onDisconnectedFromRoom () is called on the host device, so I think the game is automatically canceled, which is sad because I like to keep playing until the minimum number of players ...

Is there a way to prevent this?


source to share

2 answers

Strange behavior was caused by the installation of AutomatchCryteria. I removed it and now it behaves well



In the onDisconnectedFromRoom () callback, you get a Room object. You can check how many players are left in the room by calling

int count = room.getParticipantIds().size();


If the players are more than minimal, keep playing.



All Articles