FirebaseListAdapter not pushing individual items for chat app - Firebase-Ui 3.1

后端 未结 2 484
难免孤独
难免孤独 2020-11-22 03:47

I am making a chat app on Android that uses google firebase to store messages that users write to each other. To display these messages to the users I read them from the dat

2条回答
  •  时光说笑
    2020-11-22 04:02

    To let the FirebaseRecyclerAdapter and FirebaseListAdapter show the data on the activity

    You need to use this:

    @Override
    protected void onStart() {
    super.onStart();
    adapter.startListening();
    }
    
    
    @Override
    protected void onStop() {
    super.onStop();
    adapter.stopListening();
    }
    

    Since FirebaseListAdapter uses a listener to check for changes in the firebase database, then to being listening for data you need to add adapter.startListening() inside the onStart() to be able to show the data in the listview.

    Then inside onStop() (when activity is stopped), you can use adapter.stopListening() to remove the listener and the data in the adapter.

    Check this for more info: Adapter LifeCycle

    Note:

    If after using the above, you get a nullpointexception or cannot resolve symbol, you have to declare adapter as global variable and please check the below answer: Error in startListening()

提交回复
热议问题