I'm using Firestore shards to keep track of the number of documents in a collection. How do I convert the task it returns into a String?
My method (same as Firebase Documentation):
public Task<Integer> getCount(final DocumentReference ref) {
// Sum the count of each shard in the subcollection
return ref.collection("shards").get()
.continueWith(new Continuation<QuerySnapshot, Integer>() {
@Override
public Integer then(@NonNull Task<QuerySnapshot> task) throws Exception {
int count = 0;
for (DocumentSnapshot snap : task.getResult()) {
Shard shard = snap.toObject(Shard.class);
count += shard.count;
}
Log.d(TAG, Integer.toString(count));
return count;
}
});
}
correctly logs the count as follows: D/saveMessageSent: 1
However, when I call the getCount method somewhere else like so:
Log.d(TAG, String.valueOf(getCount(counterDocRef)));
then the log output is:
D/saveMessageSent: com.google.android.gms.tasks.zzu@8673e29
I cannot seem to convert it into a String, as it says it's a
com.google.android.gms.tasks.Task<java.lang.Integer>
How do I get around this so when I call getCount it gives me an int I can use?