Hi,
I'm working on a metronome application, so I need a rather accurate
time-measuring system to fire the metronome sound at the right time.
Actually I found a solution, but I'm wondering if my method will not
be cpu consuming. Here is the code snippet :
t = new Thread() {
public void run() {
long neededTime = 0;
while(isRunning){
long curTime = SystemClock.uptimeMillis();
if(curTime>=neededTime){
neededTime = curTime + (60000/tempo);
playSound(clickSoundId,100);
incrementBeat();
mHandler.post(mUpdateUi);
}
}
}
};
t.setDaemon(true);
t.start();
You can see I set up a semi-infinite loop with rather frequent
accesses to uptimeMillis() . I chose this method after having some
issues with sleep() which is not accurate enough. When I want to stop
the metronome, I just have to set isRunning to false.
How can I evaluate the impact of this on CPU and battery ?
Thanks a lot.
Rgds, Alex
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en