我正在使用Firebase for Android。我有一堆异步调用,我需要同时启动,但如果我启动它们,Android会崩溃。因此,我需要将它们放入某种队列中。以下是Firebase Java代码:
for (int i = 0; i < 1000; i++) {
Task<Uri> currentTask = imageStorageRef[i].getDownloadUrl();
// add tasks to a queue here rather than starting the addOnSuccessListener?
// taskQueue.add(currentTask);
// this is the asynchronous call which I cannot start too many of at the same time, or it will crash
currentTask.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String profileImageUrlNew = uri.toString();
MatchesObject obj = new MatchesObject(userIdFinal, nameFinal, profileImageUrlNew, cityStateFinal, convoIdFinal);
resultsMatches.add(obj);
mMatchesAdapter.notifyDataSetChanged();
}
});
}
我应该使用哪种队列?如何从队列中退出某些内容?我如何确保当队列中的空间释放时,我可以在下一个异步事件中添加?
我已经阅读过有关BlockingQueue和AsyncQueue的内容,但我还没有得到它们。