我在下面的代码中从SnapshotsClient获取数据作为字节数组。通常,addOnCompleteListener会通话一分钟或更长时间。有时效果很好。字节数组的长度是81我认为它不是大数据。当设备没有互联网连接时,一切都还不错。我不明白为什么要花很多时间?
void loadSnapshot() {
loading.setVisibility(View.VISIBLE);
SnapshotsClient snapshotsClient =
Games.getSnapshotsClient(this, GoogleSignIn.getLastSignedInAccount(this));
int conflictResolutionPolicy = SnapshotsClient.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED;
snapshotsClient.open("userInfoData", true, conflictResolutionPolicy)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("TAG", "Error while opening Snapshot.", e);
}
})
.continueWith(new Continuation<SnapshotsClient.DataOrConflict<Snapshot>, byte[]>() {
@Override
public byte[] then(@NonNull Task<SnapshotsClient.DataOrConflict<Snapshot>> task) throws Exception {
Snapshot snapshot = task.getResult().getData();
try {
return snapshot.getSnapshotContents().readFully();
} catch (IOException e) {
Log.e("TAG", "Error while reading Snapshot.", e);
}
return null;
}
}).addOnCompleteListener(new OnCompleteListener<byte[]>() {
@Override
public void onComplete(@NonNull Task<byte[]> task) {
try {
if (task.getResult().length == 0) {
userInfo = new UserInfo(1, 0, 120);
} else {
userInfo = ParcelableUtil.unmarshall(task.getResult(), UserInfo.CREATOR);
}
//UI changes
}
} catch (Exception e) {
}
}
});
}
https://developers.google.com/games/services/android/savedgames