LucaMs Expert Licensed User Longtime User Sep 3, 2018 #1 Can an empty process globals array of Timers be used and add new timers to it this way? Code: Copy Sub Process_Globals Privare arrTimers(20) As Timer End Sub Public Sub AddTimer(EventName As String, Interval As Int) Dim tmr As Timer tmr.Initialize("tmr", Interval) arrTimers(n) = tmr End Sub (In the example I don't use EventName; I would use it "later". Also "n"... just an example) A private object (tmr in AddTimer) added to a global array, uhm... thinking... ArrTimers will store references to timer objects, which are initiliazed as private. Well, I don't know; this is the reason for this question Also, I would prefer to use a Map to store the timers, but this could be even worse, I think.
Can an empty process globals array of Timers be used and add new timers to it this way? Code: Copy Sub Process_Globals Privare arrTimers(20) As Timer End Sub Public Sub AddTimer(EventName As String, Interval As Int) Dim tmr As Timer tmr.Initialize("tmr", Interval) arrTimers(n) = tmr End Sub (In the example I don't use EventName; I would use it "later". Also "n"... just an example) A private object (tmr in AddTimer) added to a global array, uhm... thinking... ArrTimers will store references to timer objects, which are initiliazed as private. Well, I don't know; this is the reason for this question Also, I would prefer to use a Map to store the timers, but this could be even worse, I think.
Erel B4X founder Staff member Licensed User Longtime User Sep 3, 2018 #2 You can store the timers in any way you like. Use a List or a Map. Just don't store the timers in Sub Globals as the reference will be lost when the activity is recreated and the timer will continue to tick. Upvote 0
You can store the timers in any way you like. Use a List or a Map. Just don't store the timers in Sub Globals as the reference will be lost when the activity is recreated and the timer will continue to tick.