我具有此功能来返回Firestore端点处的节点数,但似乎无法正常运行。当前,端点处的节点数为1。这里是函数
public static int getInvoicesCount(String uid)
{
final int[] count = new int[1];
FirebaseFirestore firestore;
firestore = FirebaseFirestore.getInstance();
CollectionReference invoicesRef = firestore
.collection("invoices");
Query query = invoicesRef.whereEqualTo("creator_id",uid);
Task<QuerySnapshot> task = query.get();
task.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful())
{
if(task.getResult().isEmpty())
{
count[0] = 0;
Log.d("counter",String.valueOf(count[0]));
}
else {
Log.d("counter is",String.valueOf(task.getResult().size()));
count[0] = task.getResult().size();
}
}
}
});
return count[0];
}
在else语句中记录count [0]的值将给出1,但是函数末尾的返回值仍然是0而不是1;