问题
I am doing a push action with setValue.
mFirebaseDatabaseReference.child("loccheck").push().setValue(cloc);
How do I retrieve the unique string created? P.S. I know how to do it with a push without setValue:
String key = mDatabase.child("posts").push().getKey();
回答1:
You can get the unique key after you push like
DatabaseReference newDatabaseReference = mDatabaseReference.child("loccheck").push();
newDatabaseReference.getKey();
or with setValue()
mDatabaseReference.child("loccheck")
.push()
.setValue(cloc, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError,
DatabaseReference databaseReference) {
String uniqueKey = databaseReference.getKey();
}
});
来源:https://stackoverflow.com/questions/43362401/firebase-get-key-string-of-a-push