I answered you but I don't see my message.. I hope it's OK :s On 29 déc, 03:22, Dianne Hackborn <hack...@android.com> 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 <alex.cen...@gmail.com> 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 android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > Dianne Hackborn > Android framework engineer > hack...@android.com > > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en