firebase Keepsync(true)不会更新数据

时间:2019-05-08 10:18:06

标签: android firebase-realtime-database

作为标题,即使我在查询前使用Keepsync(true),但 firebase 总是得到错误的值(以前的值)

这是我的代码:


    ROOT_REF.child(CHILD_SETTINGS).child(Member.getUser_id())
                        .child(getMyUID()).keepSynced(true);

                ROOT_REF.child(CHILD_SETTINGS)
                            .child(Member.getUser_id()).child(getMyUID())
                            .addListenerForSingleValueEvent(new ValueEventListener() {
                                @Override
                                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                                    if (!dataSnapshot.hasChild(NO_MAKING_GROUP_SETTING))
                                        validList.add(Member);
                                    else unvalidList.add(Member);

                                    if (validList.size()+unvalidList.size()==mMemberToCheck.size()) {

                                        mValidCallBack.OnCallBack(validList);
                                        mUnValidCallBack.OnCallBack(unvalidList);

                                    }

                                }

                                @Override
                                public void onCancelled(@NonNull DatabaseError databaseError) {

                                }
                            });

这是更新值代码:

ROOT_REF.child(CHILD_SETTINGS)
                    .child(getMyUID()).child(user_to_prevent)
                    .child(NO_MAKING_GROUP_SETTING)
                    .setValue(true);

// remove when I want to allow user to notify me 

   ROOT_REF.child(CHILD_SETTINGS)
                    .child(getMyUID()).child(user_to_allow)
                    .child(NO_MAKING_GROUP_SETTING)
                    .removeValue();

这是数据库

enter image description here

更新::我认为这篇文章可以帮助您:Firebase Offline Capabilities and addListenerForSingleValueEvent

0 个答案:

没有答案