如何在FiRESTORE中计算集合下的文档数?
FirebaseFirestore db = FirebaseFirestore.getInstance(); final CollectionReference postsCollection = db.collection("Posts"); final TaskCompletionSource<Integer> source = new TaskCompletionSource<>(); new Thread(new Runnable() { @Override public void run() { int fromWhereToStart = postsCollection.get().getResult().size(); source.setResult(fromWhereToStart); } }).start(); Task<Integer> task = source.getTask(); task.addOnCompleteListener(new OnCompleteListener<Integer>() { @Override public void onComplete(@NonNull Task<Integer> task) { Log.e("Z_fromWhereToStart", "= " + task.getResult()); } });
java.lang.IllegalStateException: Task is not yet complete
IllegalStateException
?
一只甜甜圈