Depending on how many commits occurred between the two versions, you may need to resolve several conflicts in this loop. He must eventually stop :) It can take a long time.
See https://developers.google.com/games/services/android/savedgames#handling_saved_game_conflicts for more details.
// Some large number to be defensive against an infinite loop. static final int MAX_SNAPSHOT_RESOLVE_RETRIES = 100; Snapshots.OpenSnapshotResult result; result = Games.Snapshots.open(googleApiClient, "save", true).await(); Snapshot snapshot = processSnapshotOpenResult(result, int retryCount); Snapshot processSnapshotOpenResult(Snapshots.OpenSnapshotResult result, int retryCount) { Snapshot mResolvedSnapshot = null; retryCount++; int status = result.getStatus().getStatusCode(); Log.i(TAG, "Save Result status: " + status); if (status == GamesStatusCodes.STATUS_OK) { return result.getSnapshot(); } else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONTENTS_UNAVAILABLE) { return result.getSnapshot(); } else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) { Snapshot snapshot = result.getSnapshot(); Snapshot conflictSnapshot = result.getConflictingSnapshot(); // Resolve between conflicts by selecting the newest of the conflicting snapshots. mResolvedSnapshot = snapshot; if (snapshot.getMetadata().getLastModifiedTimestamp() < conflictSnapshot.getMetadata().getLastModifiedTimestamp()) { mResolvedSnapshot = conflictSnapshot; } Snapshots.OpenSnapshotResult resolveResult = Games.Snapshots.resolveConflict( mGoogleApiClient, result.getConflictId(), mResolvedSnapshot).await(); if (retryCount < MAX_SNAPSHOT_RESOLVE_RETRIES) { // Recursively attempt again return processSnapshotOpenResult(resolveResult, retryCount); } else { // Failed, log error and show Toast to the user String message = "Could not resolve snapshot conflicts"; Log.e(TAG, message); Toast.makeText(getBaseContext(), message, Toast.LENGTH_LONG).show(); } } // Fail, return null. return null; }
Clayton wilkinson
source share