I am having trouble getting the documentId for an added document. The add is working correctly, but the logs aren't posting and the documentId is returning null.
Here is what I have tried:
String rideKey = postRideInfo();
public String postRideInfo()
{
HashMap map = new HashMap();
map.put("customerId", userId);
map.put("ended", false);
db.collection("ride_info").add(map).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
rideKey = documentReference.getId();
Log.v(TAG,"Ride Key:"+rideKey);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.v(TAG,"Add failed.",e.getCause());
}
});
return rideKey;
}
What am I missing?