Callbacks for FirebaseRecyclerAdapter not running

Going through the Code Lab for Firebase Android Friendly Chat - at https://codelabs.developers.google.com/codelabs/firebase-android/ - I have a problem when none of the callbacks reach / call for step 7: Reading messages

By executing the / android -start project, I can go through the first steps 2-6:

  • Overview
  • Get sample code
  • Import Starter App
  • Create a Firebase Console Project
  • Launch the starter app
  • Enable authentication (Android application added with package name and SHA1 through project console, etc.)

However, when I go to step 7, none of the calling calls are called. I run the application and the login / logout steps work.

I imported initial_messages.json as indicated there, and copied the code exactly for step 7 (several attempts to make sure that maybe I did not miss something along the way), and then even tried to finish / android. There is also the same question when callbacks never start, and so the spinner just hangs there.

Since there is so much code, I will post sections in which I expect the callback to be executed. Can someone please advise what I am missing here? And no problem - if that helps add more code that I have. thank you for reading

  // mProgressBar.setVisibility(ProgressBar.INVISIBLE); // New child entries mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); SnapshotParser<FriendlyMessage> parser = new SnapshotParser<FriendlyMessage>() { @Override public FriendlyMessage parseSnapshot(DataSnapshot dataSnapshot) { ... } }; ... DatabaseReference messagesRef = mFirebaseDatabaseReference.child(MESSAGES_CHILD); ... FirebaseRecyclerOptions<FriendlyMessage> options = new FirebaseRecyclerOptions.Builder<FriendlyMessage>() .setQuery(messagesRef, parser) .build(); mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(options) { @Override public MessageViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { ... } @Override protected void onBindViewHolder(final MessageViewHolder viewHolder, int position, FriendlyMessage friendlyMessage) { .... } }; mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { ... } }); mMessageRecyclerView.setAdapter(mFirebaseAdapter); 
+5
source share
1 answer

FirebaseUI version 3.0 introduced a new lifecycle policy for FirebaseRecyclerAdapter . So now you need to explicitly call startListening() and stopListening() on the adapter to instruct it to start and stop retrieving data from the database.

From the FirebaseUI 3.0 Upgrade Guide :

Adapter life cycle - in previous versions, adapters started listening immediately after the instance was created and had a cleanup() call to stop listening. In 3.x, you must explicitly call startListening() and stopListening() or pass LifecycleOwner to the parameter constructor.

This is a very recent release, and it looks like Code Lab has not yet been updated to reflect this violation. I raised this as a problem in the firebase/friendlychat-android GitHub repository .

+2
source

Source: https://habr.com/ru/post/1272680/


All Articles