Firebase / Android - 由UID加载用户

时间:2016-06-04 19:10:31

标签: android firebase

我只找到了加载当前登录用户的代码段:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

但是,如果我需要加载其他用户的数据,例如图像路径和名称,该怎么办?我想用他们的UID加载它们。

我当然可以自己保存数据:

-> users
    -> UID
        -> imagePath
        -> name

但我认为可能有办法使用FirebaserUser类。

我实际上认为必须有某种方式,the most recent records first

1 个答案:

答案 0 :(得分:2)

There's no way to do this directly using FirebaseUser class. The old docs of Firebase 1.0 (Before it was acquired by Google) mentioned that exact scenario and the possible solution. The current doc is not completed yet.

The solution was to save the user's data in the Real-time database keeping the uid as the key. So when you need the data of another user, you'll just have to remember their UID and can search for their data (Exactly like how you mentioned in the question description).

I searched the other way to do that without using Real-time database when I started working on my own app, however after finding no other method and reading the old doc, I gave up and used the database way. Trust me it's way easier and flexible to use the database, instead of hacking your way to avoid using it altogether.