英文:
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<ScoreSubmissionData>() {
@Override
public void onSuccess(ScoreSubmissionData data) {
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论