Switch status returns to default value when I exit the screen

Hello guys,

I created an app that I can use to switch on/off appliances using FIrebase and Arduino.

My issue is this: After toggling the switch and I leave the screen that has the switch button, maybe by pressing the back button or navigating to another screen. By the time I launch the screen with the switch again, its status automatically turns to FALSE (the default status), the same thing happens if my Switch value is set to default TRUE in my block properties, the switch status automatically turns to TRUE too.

This does not affect the actual function, i.e the switch toggling automatically to FALSE doesn’t switch off the device it’s controlling

Please help.

That is because each time you access the app, it is a new session, so will set all the initial default values.

What you need is to have the initialize block access the database and get the value as they were last saved from there. You also need to defeat the processing of onValueChange event since running the app may have the Switch13 initialize as different from the default, since it needs to get BACK the saved value (however, your logic onValueChange can be made to process it and not appear something changed if it indeed was only a return to the previous state.

One last thing: your blocks are clearly derived from the X thunkable environment, but you posted this question on the Classic Thunkable forum.

2 Likes

Hi, @olasupoayobami02fa! :wave:

Since you also posted in the #thunkable-cross category, I request @domhnallohanlon to remove this old topic. It belongs to Thunkable-Cross category.

Thanks! :blush:

Thank you!