- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个问题,就是 onChildAdded() 被无缘无故地调用,并且当添加某些东西时它确实工作正常
这是监听器:
comment = new Firebase(MY_URL).child("Comments").child(channel);
childEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot != null && dataSnapshot.getValue() != null) {
try {
comment = new ObjectMapper().writeValueAsString(commentObject);
System.out.println("onChildAdded"+comment +" s"+s);
} catch (JSONException e) {
e.printStackTrace();
}catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}
//the other call backs
};
comment.addChildEventListener(childEventListener);
这是我添加监听器的初始化代码:
@Override
public void onResume() {
super.onResume();
setupFireBaseListener(channel);
}
这是我删除监听器的方式:
@Override
public void onDetach() {
super.onDetach();
comment.removeEventListener(childEventListener);
}
请注意,我在 Application 类上调用了此方法:
Firebase.setAndroidContext(this);
这是我打印的数据:
onChildAdded{"name":"osama raddad","comment":"hi","user_id":"11"} s-K7qX32GeNLEvY4IDtnn oldData
onChildAdded{"name":"osama raddad","comment":"how","user_id":"11"} s-K7qX3UCI6vlcS5kfBdG oldData
我的firebase客户端sdk版本是2.2.1
最佳答案
onChildAdded
不仅会在您连接后为每个添加的 child 触发,还会为每个现有 child 触发。
以下来自 Firebase 文档。
...the
onChildAdded
event is triggered once for each existing child and then again every time a new child is added to the specified path.
如果您只需要新添加的项目,则需要在每个项目中包含时间戳,然后执行 orderByChild("timestamp").start(currentTimestamp)
查询。
关于android - onChildAdded 回调被调用但没有添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34761504/
我有一个问题,就是 onChildAdded() 被无缘无故地调用,并且当添加某些东西时它确实工作正常 这是监听器: comment = new Firebase(MY_URL).child(
我想在我的 firebase 数据库中获取“服装”引用下的所有 firebase 节点。为此,我将 ChildEventListener 附加到引用,并在 onChildAdded 回调中将 Clot
我的代码有问题,不知道是不是因为onChildAdded或者RecyclerView才搞定的 简单地我想在 RecyclerView 上显示消息收件箱,其中包含我从其他用户收到的所有消息,每条消息都包
我正在使用 Firebase 开发一个实时检索数据的应用程序。我有 2 个设备,并连接到 Firebase,当第一个设备向 Firebase 添加一些数据时,第二个设备的工作是获取这些数据。但它始终为
如果我的 firebase 引用中存储了一个包含 50,000 个项目的列表,并且自上次客户端在线和监听以来已将 5 个项目添加到该列表中,我必须使用哪个回调以便仅触发它对于已添加的 5 个新项目?
我正在 SearchTextView OnQueryListener 中调用 OnChildAdded 方法,该方法使用 OnChildAdded 方法在对话框中搜索和显示记录。但是当我运行代码时,O
public class DataService { private static DataService ourInstance = new DataService(); priva
我在我的项目中使用 Database Firebase。我对 onChildAdded 非常困惑。我有这样的代码: mEventListener = new ChildEventListener()
如何处理 firebase android 中的 onChildAdded 事件。下面是我的数据库json结构 { message{ "id"=10;
假设我有一个 Firebase 数据库位置 /foo,现在它下面有五个 child 。我预计在接下来的几分钟内会添加更多的 child 。我在这个数据库引用上有一个子事件监听器,当我按预期添加监听器时
我正在尝试执行一些基本的 Firebase 操作,但是 childEventListener 的行为不符合预期。 我有一个餐厅订单列表,我使用 Firebase 查询和 ChildEventListe
我将 firebase ChildEventListner 用于聊天应用程序。在这个应用程序中,我在 onChildAdded 中传递条件,即如果消息 senderId 添加的新 child 比在 A
firestore是否支持(添加文档监听器),就像firebase实时 firebase real time 有这样的方法 public void onChildAdded(DataSnapshot
考虑以下代码示例: // Get a reference to our posts Firebase ref = new Firebase("https://docs-examples.firebas
我是 Firebase 的新手,正在做一个简单的项目。我有一种方法可以从 Firebase 获取教师列表并将他们的电子邮件添加到 ArrayList 并返回。 public ArrayList get
这是显示输出的控制台屏幕截图,即添加到其中一个用户的消息目录中的子项。 另外,必须注意的是,我显示了控制台的非常短的部分,因为控制台为每条消息显示类似的输出。如果需要更多屏幕截图来澄清,请告诉我,我会
每当我使用 updateChildren() 方法时,我的 onChildAdded() 方法似乎都不起作用。它与 push().setValue() 方法配合使用。这两种方法都可以将数据发送到 Fi
我正在按照以下代码向 Firebase 添加新数据 updateChildren(childUpdates, new DatabaseReference.CompletionListener() {
我是一名优秀的程序员,十分优秀!