Firebase get push key string

I am doing a push action with setValue.

mFirebaseDatabaseReference.child("loccheck").push().setValue(cloc);

      

How do I get the unique string created? Postscript I know how to do this using push without setValue:

String key = mDatabase.child("posts").push().getKey();

      

+3


source to share


1 answer


You can get a unique key after clicking the button

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();
            }
        });

      

+1


source







All Articles