Firebase get key string of a push

こ雲淡風輕ζ 提交于 2019-12-22 05:33:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!