我的OpenFeint方法之一用于恢复排行榜数据,需要异步回调到一个方法,该方法应修改我的本地变量(使用一个很棒的hack)。我的问题现在是,一旦回调被调用,执行就会继续进行,并且由于分数值尚未更改,它将返回nullPointer。有没有办法使所有内容同步或从主函数返回回调值?
回调函数定义:http://m.the9.com/ioshelp/Android_zh/doc/com/openfeint/api/resource/Leaderboard.GetUserScoreCB.html
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;
}
回调函数定义:http://m.the9.com/ioshelp/Android_zh/doc/com/openfeint/api/resource/Leaderboard.GetUserScoreCB.html
getScoreLeaderBoard
函数,那么是的,它会等待onSuccess
事件发生。 - zapl