Android Question Can this code be improved?

D

Deleted member 103

Guest
Hi,

This code is meant to be a countdown timer that should trigger a beep every full second.
I've tried a "timer" and a "do while" loop, but the performance is not so good in both.

The beep has a delay of up to 2 hundredths of a second.
Is there a way to reduce this delay?

BeepTimer.JPG
 

Attachments

  • Beep-Example.zip
    8.4 KB · Views: 434

ilan

Expert
Licensed User
Longtime User
Well, with this trick I have now improved my code. :)
All you have to do is update the label "lblClock" every 100ms and the world looks completely different. :D
The timer now gives just as good results as the threading library. ;)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Timer-IntervalMSec= 9999
b200.Beep
Timer-IntervalMSec= 8999
b200.Beep
Timer-IntervalMSec= 7999
b200.Beep
Timer-IntervalMSec= 6997
b200.Beep
Timer-IntervalMSec= 5999
b200.Beep
Timer-IntervalMSec= 4997
b200.Beep
Timer-IntervalMSec= 3999
b200.Beep
Timer-IntervalMSec= 2997
b200.Beep
Timer-IntervalMSec= 1996
b200.Beep
Timer-IntervalMSec= 997
b200.Beep
b500.Beep
This task took: 10004 ms
Thread-IntervalMSec= 9998
b200.Beep
Thread-IntervalMSec= 8999
b200.Beep
Thread-IntervalMSec= 7999
b200.Beep
Thread-IntervalMSec= 6997
b200.Beep
Thread-IntervalMSec= 5999
b200.Beep
Thread-IntervalMSec= 4997
b200.Beep
Thread-IntervalMSec= 3999
b200.Beep
Thread-IntervalMSec= 2997
b200.Beep
Thread-IntervalMSec= 2000
b200.Beep
Thread-IntervalMSec= 999
b200.Beep
b500.Beep
This task took: 10002 ms
** Service (smhomeclock) Start **

Yes changing the interval will give a whole different result.

The sleep function is also good enough when using 100ms. It is also simpler to handle.
 
Upvote 0
D

Deleted member 103

Guest
The sleep function is also good enough when using 100ms. It is also simpler to handle.
Not really, because it does not happen that a beep at 10sec. comes, but only at 9.9sec. :(
 
Upvote 0
Top