2016-05-26 17 views

cevap

5

İki sürüm arasında kaç tane işlem olduğuna bağlı olarak, bu döngüde birden çok çakışmayı çözmeniz gerekebilir. nihayetinde durmalıdır :) Bu uzun zaman alabilir. Daha fazla ayrıntı için

bkz: 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; 
} 
+0

Önemli olan nokta değil. –

+0

Kaç yineleme yaptı? Bir günlük paylaşabilir misin? –

+0

Tamam, vay. Şimdi yaptı. Telefonum 30 dakikadan fazla bir süre orada kalıyor, bu yüzden 100 tekrarlamayı tahmin ediyorum. –

1

birden düzeltmeleri gerekiyor anlaşılan Google Play Hizmetleri uygulamasında bir hata var. Lütfen Google’ın dahil olduğu bu tartışmaya bakın: GitHub discussion and fix info

İlgili konular