我有以下代码:
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();
}
}但是,这段代码一直卡在while循环中。result的状态一直是STATUS_SNAPSHOT_CONFLICT。对于这件事为什么不解决,有什么想法吗?
发布于 2016-05-26 18:41:07
根据两个版本之间发生了多少次提交,您可能需要解决该循环中的多个冲突。最终应该停止 :)这可能需要花费很长时间。
有关详细信息,请参阅:冲突
// 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;
}发布于 2016-10-06 12:27:50
显然,Google应用程序中存在一个bug,需要多个修复。请参阅Google参与的讨论:GitHub讨论和修复信息
https://stackoverflow.com/questions/37467990
复制相似问题