# RealtimeDB DataChanged Refresh Issue when reopen screen

**URL:** https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492
**Category:** Questions about Thunkable X
**Tags:** firebase
**Created:** [December 12, 2021, 12:28pm UTC](https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492 "2021-12-12T12:28:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![paulovaz72](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/paulovaz72/32/119071_2.png) [@paulovaz72](https://community.thunkable.com/u/paulovaz72)
#### Post date: [December 12, 2021, 12:28pm UTC](https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492/1 "2021-12-12T12:28:43Z")

</div>

Hi Thunkers!

I’m having a problem when refreshing a dashboard in my home screen.

I put the listener on Screen start that calls the action to be performed. I also put a call to perform the action when the screen opens or reopens.

When the app starts, If change the data (directly in Firebase console for example), the “data changed” block works perfectly. But If I move to another screen, and return, the data changed does not work anymore. Only if I restart the app.

Below the blocks of my app with some comments.

 ![block screenshot](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/f/7f3c0b3a81c0f651aa5372c745983cccfc8a247b.png)

Any idea why the refresh stops to work when I return to the 1st screen?

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [December 12, 2021, 12:43pm UTC](https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492/2 "2021-12-12T12:43:59Z")

</div>

I did not understand your issue.

The screen `Opens` block calls your function which only reads from the database and does not change anything in it so it will not activate the `Changed` event.

How are you testing the `Data Changed` if working or not?

---

<div class="post-metadata">

### Author: ![paulovaz72](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/paulovaz72/32/119071_2.png) [@paulovaz72](https://community.thunkable.com/u/paulovaz72)
#### Post date: [December 12, 2021, 9:20pm UTC](https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492/3 "2021-12-12T21:20:09Z")

</div>

@muneer I’m changing the data directly in Firebase console in parallel to my app, just to simulate another user changing the data at same time.

Let me try explain the order the things happens:

1. I start the app, and it loads correctly the data from Firebase and update the dashboard at a screen called “home”. My dashboard is just a list of labels that loads directly from Firebase. And from this screen I eventually jump to other screens, and return later to this home screen.

2. When in the home screen, if I manipulate the data directly below the key “dashboard” Firebase console, the blocks that updates my dashboard works instantly. I can change 100 times and the data is updated, that means the “Realtime datachanged” block works.

3. So when I navigate to another screen, and change the data via the new screen, when I return to the home screen, the data is updated ok (because I have the “when open” block that force the dashboard to update). But…

4. After navigate to another screen, and returns to the home screen the “data changed” will not trigger the blocks that updates the dashboard when I manipulate the data via Firebase anymore.

Hope to helped you to understand the issue.

Basically:

> > When in Home screen 1st time \>\> update data works anytime via Firebase

> > When in Home screen \>\> go to another screen and update the data \>\> when return to home screen data is updated

> > Home screen \>\> go to another screen and update data \>\> return to the home screen and update data \>\> in home screen update data in firebase directly does not work anymore.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [December 13, 2021, 10:02am UTC](https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492/4 "2021-12-13T10:02:19Z")

</div>

Thank you for the detailed explanation.

I can tell you that will not work for **two** reasons.

1- Starts and Opens  
These names are confusing, actually they work different that what people think. One thing for sure that if you go back to your screen using a button which uses the `Navigate to screen` block then both `Starts` and `Opens` will execute. the only time the `Starts` will not execute is when you go back to the screen using the `screen swipe gesture`.  
To overcome this issue create an `app variable` for example **Listener Active** and set it to **FALSE** whenever you have you screen active first check if this variable is false to to execute the listener block and immediately set this variable to **TRUE**. This way you will avoid adding the listener multiple times.

2- Data from the listener should be saved to variables  
Thunkable does not allow accessing the components of one screen from another screen. So if you are in screen 2 and the `DataChanged` block is in screen 1 it will execute when the data is changed in Firebase but it will fail to update labels in screen 1 because you are currently using screen 2.  
The remedy to this is to save the information into a variable and when the screen becomes active, you update the labels from the variable that was changed by the `DataChanged` block.

Hope you find it clear.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)
#### Post date: [March 13, 2022, 10:02am UTC](https://community.thunkable.com/t/realtimedb-datachanged-refresh-issue-when-reopen-screen/1652492/5 "2022-03-13T10:02:47Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
