Missing or Skipping seconds in countdown timer and precision of decimal numbers

875 views
Skip to first unread message

Yusuf

unread,
Sep 5, 2014, 6:31:06 PM9/5/14
to mitappinv...@googlegroups.com
Hi,

I am facing strange problem. for my daily routine, i always need timer and i was trying to build one for myself using AI2.

I have tried to replicate exactly following timer examples: 





I noticed, just by chance, that my count down timer is skipping 1 o 2 seconds in between at random intervals. eg.  downcounting from 15,  it will start  14,13,12,10, 9,8,7,6,4,3,2,1    here 11th and 5th second is skipped.  this happens randomly consequently my counted one minute is less than actual 1 minute.  

i read all notes given on above websites ---

Working with the Timer I find that the TimerInterval is from the time you exit the .Timer procedure until it restarts, ie if TimerInterval is 1000ms (1 second) and it takes 45ms for the phone to do your blocks the total time between any one block will be 1045ms. 

Remember that your App is not the only thing running on the phone. If it's time for your Timer to go off and the phone is busy doing something else, your event will be delayed until the phone can get to it. 

But i am wondering, why my other timer apps run perfectly and not the one created in AI2 ?   Is it related to the precision of numbers handled by AI2 ?   
I have downloaded this timer and run on two different phones, but even this skips seconds while counting. 

I am facing same problem with other app i am building for my daily work, converting basic metric units, e.g. millisec to hours, picolitre to litre  so on. i am noticing that the values of division or product are not displayed accurately. i tried converting to decimal function but it displays so many zeros after actual value which makes my screen aesthetically very bad and confusing.

lastly a quick question, I need to display values in text box which are very low or very high e.g. 0.000001 in scientific notation like 1E-6. how can i do that ? because using label i can do it but when i want to display in text box it shows all those annoying zeros , and if i make set decimal 10 digits or so then i see long trail of zeros(e.g.  0.0000123000)

any suggestions.

regards
yusuf


SteveJG

unread,
Sep 6, 2014, 4:06:58 PM9/6/14
to mitappinv...@googlegroups.com
AI2 apps are event driven, only one thing can occur at a time.  Apps made with Eclipse or Android Studio can simultaneously process different data streams (multi-threading).  AI2 can not.   See http://en.wikipedia.org/wiki/Event-driven_programming

This answers:  But i am wondering, why my other timer apps run perfectly and not the one created in AI2 ?   Is it related to the precision of numbers handled by AI2 ?   
I have downloaded this timer and run on two different phones, but even this skips seconds while counting. 

So AI2 event timers are not precise but can be used for many applications.


AI2 has high precision mathematics.   If you do not truncate or set the decimal places, the calculations can be very accurate.  What you are posting is probably the values rounded for display.
You said: i tried converting to decimal function but it displays so many zeros after actual value which makes my screen aesthetically very bad and confusing.    So, do not convert until you want to display the value.
There are routines that can allow you to truncate the zeros using the format commands.

Again, you use the format commands to make the posted results look pretty while keeping the real result hidden in the code:  lastly a quick question, I need to display values in text box which are very low or very high e.g. 0.000001 in scientific notation like 1E-6. how can i do that ? because using label i can do it but when i want to display in text box it shows all those annoying zeros , and if i make set decimal 10 digits or so then i see long trail of zeros(e.g.  0.0000123000)



for some solutions.


Did this help?

Regards,
Steve





Yusuf

unread,
Sep 7, 2014, 9:10:57 AM9/7/14
to mitappinv...@googlegroups.com
Dear Steve,

thank you for detail guide. 
now i understand why my seconds are skipping. 

Just as an information, I have got fairly good accuracy with timer of http://puravidaapps.com/countdown.php and now it is not skipping seconds. But indeed it is not ultra accurate timer because of the valid reasons as given in your answer. 
i found after a bit of tricks that it is a matter of missing few 100ms, so i have adjusted clock1 and clock2 invervals.
what i did is to keep clock1 interval to 100ms  and clock2 interval to 1000ms.

about mathematics, yes i did realize later that by keeping numbers within program and performing adjustment at the displaying end helps.
but the about getting scientific notation is issue of Design of AI2  as explained by Hal here . apparently i have to play around to get scientific notation in text box and get rid of several trailing zeros. 

thanks for suggestions and information.

kind regards,
Yusuf


Mihai Salajan

unread,
Feb 22, 2015, 7:47:26 AM2/22/15
to mitappinv...@googlegroups.com
Hi everyone
i need a countdown from 30 min with 3 button "start" "+5min" and "-5min"
when i press "start" the timer goes from 30 min to 0 if press "+5min" it adds 5 min to remaining time but when i press "-5min" it drops 5 min from remaining time , when time reaches 0 it gives acoustic alarm and it opens a notification with 2 buttons "ok" and "close" if ok it does nothing but if "close" then closes the program

Enis

unread,
Feb 22, 2015, 5:50:40 PM2/22/15
to mitappinv...@googlegroups.com
Mihai...

You are hijacking threads and double posting.  I have removed your other post.  In the future, please do not do either again.

If you have an issue, start your own discussion up here but only ONE discussion, OK?
Reply all
Reply to author
Forward
0 new messages