2014년 12월 12일 금요일

TimerAlwaysFires problem

I am trying to create a reminder for borrowing books for our library at our University. In this screen it shows how many days are left before you can take your borrowed book back. It's always 15 days. For testing purposes I've done it in minutes.

I had a button that when the user pressed it it would start a day countdown (this case minutes as I said). TimerAlwaysFires and Timer Enabled were unticked until the user pressed the button. But it didn't work. So afterwards I had them ticked from the beginning and found a different way to approach this.

So in the When Clock2 I save in a TinyDB the time which shows in the label the user sees. I also have another label which is hidden that counts every seconds and is depended on the TimerAlwaysFires. So every second, that hidden label gets minus one. The official label though mustn't show every second but every day (this case for testing minutes) so if the modulo of the time in the hidden label divided by 60 equals zero, then a minute has passed so I assign into the label the user sees minus one minute.
I also save that label so when the application closes it will still be saved (LabelTB)

It works, every minute the official label goes minus one, if i reopen the application it will show the saved minutes but the problem is that the TimerAlwaysFires (I'm guessing) doesn;t work outside of that screen. When i tested it out before with a simper code it did and then when I mad it a little more complicated like this, it's not.

There is no other code in my screen yet but it should work. 

Any ideas? I hope I didn't confuse you!
(I have attached my code)




The Clock.TimerEnabled and Clock.TimerAlwaysFires blocks should not be inside the Clock.Timer event. They should be outside of it. Try moving them to the Screen.Initialized event, or whereever you want the the clock to start firing.



Nop its not working... for some reason the timer doesn't seem to fire at all even though I tell it to be enabled and the TimerAlwaysFires equals true. They are true even before I set them to, from the designer. The clock seems to work only when I am at the specific screen...



This information might help you solve your issue:

An AI2 timer only works on one screen.   If you want the value on another screen, you  have to pass the value to the other screen.  I do not know, but think the timer on its on screen keeps working, but I do not know.  When the screen is closed, the timer might stop firing?   I do not know.

 Consider, with AI2, what you code on separate screens are in essence, miniature apps, independent from the other screens.  An exception is the TInyDB that shares values across screens.



Use DoIt to see what the value of Modulo(time, 60) is. I suspect the counter is never incrementing because, the modulo of 15 & 60 is never equal to zero.



Nah this one is working. It always goes one minute down in the Label3 as I wanted. The only strange thing here is that the timer works only in this screen when I specifically do the TimerAlwaysFires and Timer Enabled to be true always...How do I make the timer work in other screens and how can the timer always work even when i close the application?



A timer on Screen1 still fires if you open another Screen 2. But if you close the app (e.g. press back button) it will no longer fire.

how can the timer always work even when i close the application?



댓글 1개:

  1. Hey there the firs thing that you miss is that app inventor work for
    999999999 mile seconds = 11 day
    So you must change the time interval bellow 11 days or 999999999 mile secobds

    답글삭제