Google Play Game Services unlocks the achievement - keep the unlock in the game or unlock the call () every time?

I am developing an Android game that uses the Google Play Game services.

When a player reaches, for example, 10,000 points, the achievement is unlocked. So when a player reaches 10,000 points, I call

Games.Achievements.unlock(...)

The question is what to do when the user again reaches 10,000 points in another game. Do I have to check if this achievement has already been unlocked or can I call unlock () again?

I know that the β€œServices” popup only expands when the achievement is first unlocked. But I'm worried about the quota of api calls. If, for example, I keep unlocking achievements from the general settings, I would do something like this:

if(myAchievementIsLocked){
   Games.Achievements.unlock(...)
}

? , , .

+4
2

, unlock() Play Games, , , . , unlock() - , , , Play Games .

, - , ( , ). , API, , :)

, ( AsyncTask ), ( ). , , - onSignInSucceeded() - .

11.8.0

public void loadAchievements()  {
    mAchievementsClient.load(true).addOnCompleteListener(new OnCompleteListener<AnnotatedData<AchievementBuffer>>() {
        @Override
        public void onComplete(@NonNull Task<AnnotatedData<AchievementBuffer>> task) {
            AchievementBuffer buff = task.getResult().get();
            Log.d("BUFF", "onComplete: ");
            int bufSize = buff.getCount();
            for (int i=0; i < bufSize; i++)  {
                Achievement ach = buff.get(i);
                String id = ach.getAchievementId();
                boolean unlocked = ach.getState() == Achievement.STATE_UNLOCKED;
            }
            buff.release();
        }
    });

  public void loadAchievements()  {

     boolean fullLoad = false;  // set to 'true' to reload all achievements (ignoring cache)
     float waitTime = 60.0f;    // seconds to wait for achievements to load before timing out

     // load achievements
     PendingResult p = Games.Achievements.load( playHelper.getApiClient(), fullLoad );
     Achievements.LoadAchievementsResult r = (Achievements.LoadAchievementsResult)p.await( waitTime, TimeUnit.SECONDS );
     int status = r.getStatus().getStatusCode();
     if ( status != GamesStatusCodes.STATUS_OK )  {
        r.release();
        return;           // Error Occured
     }

     // cache the loaded achievements
     AchievementBuffer buf = r.getAchievements();
     int bufSize = buf.getCount();
     for ( int i = 0; i < bufSize; i++ )  {
        Achievement ach = buf.get( i );

        // here you now have access to the achievement data
        String id = ach.getAchievementId();  // the achievement ID string
        boolean unlocked = ach.getState == Achievement.STATE_UNLOCKED;  // is unlocked
        boolean incremental = ach.getType() == Achievement.TYPE_INCREMENTAL;  // is incremental
        if ( incremental )
           int steps = ach.getCurrentSteps();  // current incremental steps
     }
     buf.close();
     r.release();
  }

API.

, , ( for, ) .

+5

.unlock(...) . , .unlock(...) - ", ".

+1

Source: https://habr.com/ru/post/1541898/


All Articles