第二次获取数据会使我的长变量增加 1,导致无法多次重新加载数据



我有一些数据获取方法,它们相互调用,以便根据先前获取的数据获取数据。

我的问题是我持有一个名为"allContestsCounterIndex"的长变量,该变量仅在 2 个特定位置递增,并且出于某种原因在第一次获取数据后,当再次单击以尝试第二次获取时,它的值以 1 开头,这意味着我无法继续,因为它使逻辑卡住了。

这是我正在使用的功能 -


private void updateContestCallCounter(long childrenCount) {
allContestsCounterIndex++;
if (allContestsCounterIndex == (childrenCount - 1)) { // at this point at the second time this variable starts with a value of 1 instead of 0
fetchWinnersFromOurValidContests();
}
}


private void fetchAllEndedStatusContests(DataSnapshot dataSnapshot) {
if (!dataSnapshot.exists()) {
// For some reason, we've reached this point with no dataSnapShot
Timber.d("dataSnapShot doesnt exists");
return;
}
long timeInSeconds = (System.currentTimeMillis() / 1000);
mEndedContests = new ArrayList<>();
long childrenCount = dataSnapshot.getChildrenCount();
for (DataSnapshot status : dataSnapshot.getChildren()) {
//fetching the status key for deeper querys inside the db
final String key = status.getKey();
checkIfContestEnded(timeInSeconds, key, new OnContestStateReceived() {
@Override
public void contestHasEnded() {
mEndedContests.add(key);
updateContestCallCounter(childrenCount);
}
@Override
public void contestStillScheduled() {
updateContestCallCounter(childrenCount);
}
});
}
}

完成重新获取数据后,应将所有计数器设置为 0。

最新更新