Multiple Listeners

Hi Thunkers,

I am trying to work out how to use Realtime listeners efficiently.

Currently, I have set up a single listener in my loading screen. I have two issues.

  1. The listener isn’t working across different screens.
  2. Any change requires a snapshot of my entire users database.

Ideally, I would like to set up multiple listeners so that I only take a snapshot of the node that has changed. I can see my data fees increase significantly doing it the way I currently have it. Any suggestions?

1 Like

I was just working throught a similar issue. A few observations and strategies for you (and those who find this thread in the future):

  1. Having multiple listeners for the Realtime DB Component on different screens results in only one of the Change Events Triggering
  2. Creating Mulitple Realtime DB Components (one for each screen) pointing to the same firebase database allows mulitple screens to update whenever data changes

Mulitple asynchronous event can be confusing. So to illustrate the point, here is a sample application:
https://x.thunkable.com/copy/5e64e2455b568f7b8bdfbd0a165d4e40

If you add your firebase Web API key and database to this sample application, you can test it to see how it work. Here are a few highlights:

I have two separate screens (cheese and crakers). Each needs to update if either the cheese or cracker branch changes (respectively). I created 2 Realtime DB components, one for cheese and one for crackers. I created 2 listeners per realtime DB. With this system I can have any number of listeners, as long as each Realtime DB has only one listener (on one screen).

The Cheese Screen and Listener


The Cracker Screen and Listener

2 Likes

Thank you @drted,

This definitely gives me something new to play with and looks to be a promising work-around. I would never have thought of using different db blocks for the same Firebase db. It seems to be working but I need to test if the listener is now being triggered twice. (I have set the same listener node for both of my screens on each individual db listener block in their respective screens.

Thanks again. It has at least given me new breath with what I can try.

PS: I had just finished merging two of my screens to overcome this problem and now I have a screen with over 2000 blocks. It is slow to respond in the UI and selecting elements from the list is a little like “where’s wally” :rofl:

3 Likes