Stack Exchange
Play Games Snapshot conflict resolution gives conflict
I've got the following code:
Snapshots.OpenSnapshotResult result;
result = Games.Snapshots.open(googleApiClient, "save", true).await();
while (result == null || !result.getStatus().isSuccess()) {
    Log.d("Snapshot", "Open snapshot");
    if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {
        Snapshot snapshot = result.getSnapshot();
        Snapshot conflictSnapshot = result.getConflictingSnapshot();

        // Resolve between conflicts by selecting the newest of the conflicting snapshots.
        Snapshot mResolvedSnapshot = snapshot;

        if (snapshot.getMetadata().getLastModifiedTimestamp() <
                conflictSnapshot.getMetadata().getLastModifiedTimestamp()) {
            mResolvedSnapshot = conflictSnapshot;
        }

        result = Games.Snapshots.resolveConflict(
                googleApiClient, result.getConflictId(), mResolvedSnapshot).await();
    }
}

However, this code keeps getting stuck in the while loop. result keeps having the status STATUS_SNAPSHOT_CONFLICT. Any ideas as to why this is not getting resolved?

Depending on how many commits have happened between the two versions, you may need to resolve multiple conflicts in that loop.  It should eventually stop :) This might take seriously long though.
For more details see: https://developers.google.com/games/services/android/savedgames#handling_saved_game_conflicts
// 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;
}


Okay, wow. Now it did. My phone just laid there for over 30 minutes, so I'm guessing about 100 iterations.

For some reason I ended up with more than 15 conflicts during the testing of my app. Keeping resolving the conflict eventually worked!

There's a bug in Google Play Services app apparently which needs multiple fixes. Please see this discussion where Google is involved:
GitHub discussion and fix info
