One of my OpenFeint methods to recover leaderboard data needs an asynchronous callback to a method that is supposed to modify one of my local variables (using a wonderful hack). My problem now is that once the CB is called the execution continues and, as the score value has not changed yet it returns a nullPointer. Any way to make everything synchronize or return the callback value from the main function?
private long getScoreLeaderBoard(String idLeaderBoard) {
for (Leaderboard l : OpenFeintX.leaderboards) {
if (l.name == null)
break;
if (l.resourceID().equalsIgnoreCase(idLeaderBoard)) {
final Score s[] = new Score[1];
l.getUserScore(OpenFeint.getCurrentUser(),
new Leaderboard.GetUserScoreCB() {
@Override
public void onSuccess(Score score) {
s[0] = score;
}
});
if (s[0] != null) // If user has no score onSuccess get a null
return s[0].score;
else
return 0;
}
}
return 0;
}
Callback definition: http://m.the9.com/ioshelp/Android_en/doc/com/openfeint/api/resource/Leaderboard.GetUserScoreCB.html