listener 在 Java Android Studio 中的位置

huangapple go评论62阅读模式
英文:

places of listener in java android studio

问题

When I replace "addOnFailureListener" and "addOnSuccessListener" in two different examples of the same code that I shared below, the top listener is wrong and the bottom one is not wrong. It hasn't happened to me before and I don't know what's causing it, what do you think I'm doing wrong?

英文:

when I replace "addOnFailureListener" and "addOnSuccessListener" in two different examples of the same code that I shared below, the top listener is wrong and the bottom one is not wrong. It hasn't happened to me before and I don't know what's causing it, what do you think I'm doing wrong?

public void submitLeaderboardScore(long score) {
            leaderboardsClient = Games.getLeaderboardsClient(getApplicationContext(), Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(getApplicationContext())));

            leaderboardsClient.submitScore(getString(R.string.leaderboard_id), score)
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            // Handle failure while submitting score
                        }
                    })
                    .addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            // Score submission successful
                        }
                    });

        }

public void submitLeaderboardScore(long score) {
            leaderboardsClient = Games.getLeaderboardsClient(getApplicationContext(), Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(getApplicationContext())));

            leaderboardsClient.submitScore(getString(R.string.leaderboard_id), score)

                    .addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            // Score submission successful
                        }
                    })

                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            // Handle failure while submitting score
                        }
                    });


        }

success listener on top
error listener on top

error : Cannot resolve method 'addOnFailureListener(OnFailureListener)'
or
Cannot resolve method 'addOnSuccessListener(OnSuccessListener<Void>)'

whichever is on top, error is displayed on it

答案1

得分: 0

尝试如下:

leaderboardsClient.submitScoreImmediate(leaderboardId, score).addOnSuccessListener(new OnSuccessListener<ScoreSubmissionData>() {
    @Override
    public void onSuccess(ScoreSubmissionData data) {
      
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
      
    }
});
英文:

try as follows

 leaderboardsClient.submitScoreImmediate(leaderboardId, score).addOnSuccessListener(new OnSuccessListener&lt;ScoreSubmissionData&gt;() {
    @Override
    public void onSuccess(ScoreSubmissionData data) {
      
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
      
    }
});

huangapple
  • 本文由 发表于 2023年6月12日 08:00:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452969.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定