The timer goes crazy the longer it works and I do not know why

41 views
Skip to first unread message

Munsen Tidoco

unread,
Mar 28, 2018, 3:17:23 PM3/28/18
to MIT App Inventor Forum
Hi. I have an app made with ai2 that connects to a MySql to send and bring information.
From the beginning, it performs this synchronization with the push of a button and thus works very well.
But now I'm trying to make it work automatically, for example; Release instruction to synchronize every 20 minutes.

The app has 8 screens. In the first, which is the one that is usually open, I put the clock changing its name to Temporizador to identify it against the other clocks that I use, one per screen. I activated the options TimerAlwaysFires and TimerEnabled, leaving TimerInterval in 10000 (ten thousand milliseconds).

In the blocks I put 2 global variables: Momento and Lapso, at the beginning I set Momento to 1 and Time in 60, that for 10,000 milliseconds is 10 min. And the Temporizador is adding 1 to the momento in each interval. At the moment when the momento reaches the Lapso, the momento is set to 1 and the instruction to go to the synchronization screen is sent. The one that identifies where it comes from and synchronizes automatically and at the end closes that screen returning to the main one.

Everything works very well the first hour, more or less. Then, it seems to be delayed or anticipated at random, getting to not synchronize in one hour or, worse and much more frequently, to synchronize several times one after the other.

I have no idea what provokes it. Navigate between the screens or leave the cel on the table without touching, it ends up going crazy.

Any ideas or suggestions?

Screen1 I susspend timer when changue screen and reactivated when back


Screen9 The sync process have 2 ways; Manual, whn click sync button or automatic, when recived a start value. In this case, when sync ending, closse screen and back to screen1.



TimAI2

unread,
Mar 28, 2018, 5:59:38 PM3/28/18
to MIT App Inventor Forum
It is difficult to see from the partial blocks you have posted exactly what is going on.
(Right click on some white space in the blocks editor to download all blocks as an image)

I would hazard a guess that you problems are twofold (2)

1. Switching screens is not being managed correctly, meaning you end up with many screens "open" at once

Use different screens wisely

If you decided to use different screens, then you should switch them correctly, else you will run out of memory after a while...      
The recommended method of switching screens in App Inventor
(Thanks Taifun)

Also see demo: multiscreen.aia

2. You are trying to create a delay with blocks, instead of using a timer to do this.
You can't use blocks to create a delay

I could be wrong, but need to see more of your blocks...

Munsen Tidoco

unread,
Mar 28, 2018, 6:55:21 PM3/28/18
to MIT App Inventor Forum
Thanks for answering. I will check that all the screens have "Close screen" in the back block. I did not know the importance of doing it and that is probably the problem.

About the number of screens (there are actually seven, I have already unified some intermediate ones), is that the application of being something very simple first has grown very fast and it has become too complex, and I have not been able to unify more screens. That by the way, almost all the screens, use the arrangements to simulate different screens.

Again, I appreciate your suggestion. I try it and return to write as it was

Abraham Getzler

unread,
Mar 29, 2018, 10:39:45 AM3/29/18
to MIT App Inventor Forum
Also see How to run an accurate metronome in the
Waiting and Timing section of FAQ

ABG
Reply all
Reply to author
Forward
0 new messages