OK, here we go again: Timers.
My problem:
I want to show various bits of information on screen. Most of the time, none will be shown, and at most, maybe a handful, but there will be dozens of such items stored in a map that will occasionally be shown. Now, when I show them, I want them to stay a few seconds, then disappear, and I want some central handling of that, so that it won't have to be re-invented in every class.
Now, I see two main ways of doing it.
* Creating one timer for each class. Well, could be done, but hardly neat.
* Set a "death time" on each item as it is shown. Then, using a single timer, check every 200 ms or so if any of them has passed their "death time". Only one timer, but iteration hundreds of items every second seems wasteful, and will make debugging a pain in the ass.
Is there any good way of doing it? I'd like some kind of "Get back to me at this time" scheduler, though, of course, not something as Heavy as starting services or lobbing intents around. However, any solution that works better is good.
Some pseudocode to try to explain what I'm doing:
Edit: In other words, what I need is something like "Fire an event at these times", where I can add times dynamically.
My problem:
I want to show various bits of information on screen. Most of the time, none will be shown, and at most, maybe a handful, but there will be dozens of such items stored in a map that will occasionally be shown. Now, when I show them, I want them to stay a few seconds, then disappear, and I want some central handling of that, so that it won't have to be re-invented in every class.
Now, I see two main ways of doing it.
* Creating one timer for each class. Well, could be done, but hardly neat.
* Set a "death time" on each item as it is shown. Then, using a single timer, check every 200 ms or so if any of them has passed their "death time". Only one timer, but iteration hundreds of items every second seems wasteful, and will make debugging a pain in the ass.
Is there any good way of doing it? I'd like some kind of "Get back to me at this time" scheduler, though, of course, not something as Heavy as starting services or lobbing intents around. However, any solution that works better is good.
Some pseudocode to try to explain what I'm doing:
B4X:
Sub Globals()
Dim NfMap as Map
End Sub
Sub Setup()
NfMap.Initialize
'Note: Different types
Dim nf as NewsFlash1: nf.Initialize: AddNfToMap(nf)
Dim nf as NewsFlash2: nf.Initialize: AddNfToMap(nf)
Dim nf as NewsFlash3: nf.Initialize: AddNfToMap(nf)
Dim nf as NewsFlash4: nf.Initialize: AddNfToMap(nf)
Dim nf as NewsFlash5: nf.Initialize: AddNfToMap(nf)
Dim nf as NewsFlash6: nf.Initialize: AddNfToMap(nf)
Dim nf as NewsFlash7: nf.Initialize: AddNfToMap(nf)
...
End Sub
Sub AddNfToMap(nf as object)
NfMap.Put(nf.Key, nf)
End Sub
Sub ShowInfo(Key as string, Message as string)
dim nf as object= NfMap.Get(Key, Message)
nf.Show(Message, 3000) 'Hide after 3000 ms
End Sub
'Something to hide nf after the time has passed???
Edit: In other words, what I need is something like "Fire an event at these times", where I can add times dynamically.
Last edited: