Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase get key string of a push

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();
like image 934
OkyDokyman Avatar asked Apr 12 '17 06:04

OkyDokyman


1 Answers

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();
            }
        });
like image 91
Linh Avatar answered Sep 23 '22 02:09

Linh