我在数据库中有这样的用户:
我尝试使用帮助程序类来读取用户 还有这种方法
public void readUser (final FirebaseUserHelper.DataStatusUser dataStatus)
{
mReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
user = (User) dataSnapshot.getValue(User.class);
dataStatus.DataIsLoaded(user,userKey);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.e("User", databaseError.getMessage() );
}
});
当我调试时,我看到引用是好的,但是不被调用了onDataChange
或onCancelled
方法。
public class FirebaseUserHelper {
private FirebaseDatabase mDatabase;
private DatabaseReference mReference;
private String userKey;
private User user;
public interface DataStatusUser
{
void DataIsLoaded( User user, String key);
}
public FirebaseUserHelper()
{
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
userKey = firebaseAuth.getCurrentUser().getUid();
mReference=mDatabase.getReference("Users").child(userKey);
}
}