【问题标题】:Firebase's onChildAdded is called as many times at startup as there are elements in the DB at the timeFirebase onChildAdded 在启动时被调用的次数与当时数据库中的元素一样多
【发布时间】:2022-06-13 22:43:37
【问题描述】:

为什么 Firebase onChildAdded 函数的调用频率与 DB 中的条目一样频繁? 我以为只有在添加新对象时才会调用此方法

  @Override
  //Have already tried the call in onCreate, same problem
  protected void onStart() {
  ref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {

        //Called up for each entry, currently 7x
        List<Places> testPlaces = new ArrayList<Places>();
            for(DataSnapshot snap : snapshot.getChildren())
          {
                testPlaces.add(snap.getValue(Places.class))

          }

  }

我也买了一个:

com.google.firebase.database.DatabaseException:无法将 java.lang.String 类型的对象转换为 com.bkoubik.fortestingall.Places 类型

【问题讨论】:

    标签: java android firebase android-studio


    【解决方案1】:

    您好,您可以点击此链接获取答案 https://payhip.com/b/Gx0Ik

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 2020-05-06
      • 2020-02-19
      • 2017-10-31
      • 2020-06-28
      • 2018-04-10
      相关资源
      最近更新 更多