Hello,
thanks you so much for looking at my problem :)
First, my application is using a SCREEN_DIM_WAKE_LOCK so the screen is
always on, yet the backlight and the keyboard are dimmed. Did you say
in this case, the battery would not be consumed ?
So, about accuracy, the fastest callback that I can set is 60ms (a
quarternote at 250 BPM tempo). I can afford a 10ms, lets say 15ms
jitter, more and it will be noticeable at this tempo. Following this
idea, I added a Thread.Sleep(10) since yesterday, to avoid too much
iterations of my timing loop :
while(isRunning){
//Do stuff...
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}//End while
Is it "better" for CPU or is it only cosmetic ?
I didn't try message posting, I'll check this immediately. Is it
suitable for so short callback times ?
I didn't specified a priority on the Thread, so I suppose it's
inherited from the parent's priority. What would be the best value for
it in your opinion ?
Regards, Alex
On 29 déc, 03:22, Dianne Hackborn <[email protected]> wrote:
> This will run the CPU at 100%. With the screen off, this will tremendously
> impact battery life. With it on, it will be at least noticeable.
>
> How accurate do you need to be? Have you tried other approaches such as
> posting messages at a time? What priority are you running your timing
> thread at (priority would be the first thing I look at when it comes to
> accuracy).
>
>
>
> On Tue, Dec 28, 2010 at 4:06 AM, Slash4 <[email protected]> wrote:
> > 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]<android-developers%[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails. All such
> questions should be posted on public forums, where I and others can see and
> answer them.
--
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