playgameservices / android-basic-samples

Google Play game services - Android samples
Apache License 2.0
971 stars 973 forks source link

How to properly cancel a realtime multiplayer match? #237

Closed MohammadAbbasKhan closed 6 years ago

MohammadAbbasKhan commented 7 years ago

2 down vote favorite How to properly cancel a realtime multiplayer match if the user cancels the match during the waiting room phase? At this time, there isn't a "room id" to call the leave API.

First a quick game is created:

Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0); RoomConfig.Builder roomConfigBuilder = configRoom(); roomConfigBuilder.setAutoMatchCriteria(am); RoomConfig roomConfig = roomConfigBuilder.build(); Games.RealTimeMultiplayer.create(getApiClient(), roomConfig); Then onRoomCreated is triggered and a waiting room is showed:

Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(getApiClient(), room, Integer.MAX_VALUE); startActivityForResult(i, RC_WAITING_ROOM); After that the user presses back, canceling the match. Then onActivityResult is triggered with RC_WAITING_ROOM and responseCode == Activity.RESULT_CANCELED.

The problem is that the match is still there, waiting for another player. If someone also starts a quick game 10 minutes later, the game will start!

How do I clean it after the user cancels?

find more details here http://stackoverflow.com/questions/24644785/how-to-properly-cancel-a-realtime-multiplayer-match?answertab=active#tab-top

mwgray commented 6 years ago

Looks like this was solved on Stack Overflow. Closing.