Activity_Pause & Resume and Timers

Cableguy

Expert
Licensed User
Longtime User
Hi, I'm using a Timer in my current project, and when the view goes into Pause, the trigger still runs, so far so good, when I resume the view, the triger still runs, so far so good, but If i cicle this 3 or 4 times, the timer gets over fired, so I had to disble my timer on Activity pause, and enable it on resume...
 

Cableguy

Expert
Licensed User
Longtime User
My timer sub is vey simple, it only increments a clock alike label, and the interval is 1000, so it fires every second, but after some cycling it was firing 4/5 times over, and I could see the labels beeing updated...
With the disable/enable trick, all works great
 

Cableguy

Expert
Licensed User
Longtime User
Yes I did, I will try to make a simplistic example of wht I mean....and hopefully reproduce the behaviour...
This happened in the device, Not in the emulator, and I did not try it in the emulator...too slow...
 

Cableguy

Expert
Licensed User
Longtime User
A very simple example, wich uses my actual Timer Tick sub, and in wich the odd behaviour is present...

Almost forgot...the odd behaviour is presente when cycling from the main activity view to the "easy" view, then back, then easy again, cycling a few times and the behaviour presents it self
 

Attachments

  • Teste Timer.zip
    5.9 KB · Views: 272
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Objects that are declared in Sub Globals are tied to the activity. Which means that when the if you declare the timers in this sub they will be recreated each time the activity is recreated.
If you declare the timers under Sub Process_Globals it will work fine as the timers will only be created once.
Timers are special objects. Most objects are correctly destroyed together with their "parent" activity. Timers however do not get immediately destroyed. Therefore each time the activity is recreated new timers are created.
 
Top