为什么我的数据快照返回空值?

时间:2018-11-02 20:20:41

标签: java android firebase

im试图使用可重用的方法从Firebase中获取一个分支

PrincipalActivity:

public class PrincipalActivity extends AppCompatActivity {
ProfilesListFragment profilesListFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);
    PrincipalActivityEvents principalActivityEvents = new PrincipalActivityEvents(this);
     DataHolder.instance.firebaseAdmin.setFirebaseAdminListener(principalActivityEvents);
    profilesListFragment = (ProfilesListFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_profilesList);
    DataHolder.instance.firebaseAdmin.downloadAndObserveBranch("Users2");

}}

Firebase方法:

 public void downloadAndObserveBranch(final String str_branch) {

     DatabaseReference refBranch = myRefRoot.child(str_branch);
     refBranch.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String clave = dataSnapshot.getKey();
         firebaseAdminListener.firebaseAdmin_BranchDownloaded(str_branch,dataSnapshot);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            firebaseAdminListener.firebaseAdmin_BranchDownloaded(str_branch,null);
        }
    });
}}

事件:

@Override
public void firebaseAdmin_BranchDownloaded(String str_branch, DataSnapshot dataSnapshot) {
    Log.v("secondactivity", str_branch + " " + dataSnapshot);
}

日志结果为{key = Users2, value = null}

为什么这样工作?

0 个答案:

没有答案