Why not just use post instead of postDelayed? That's what I use to update
display of the battery level every 10 seconds:
public class Battery_Level_Thread extends Thread {
@Override
public void run() {
while (true)
{
MainActivity.handler.post(new Runnable() {
@Override
public void run() {
MainActivity.update_battery_level();
}
});
try {
Thread.sleep(10*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
On Tuesday, October 30, 2012 7:10:57 PM UTC-5, marcpolo wrote:
>
>
> Thanks very much for the feedback.
>
> When I mentioned that I used a thread, I meant that I extended the Thread
> class with the run() method being overriden. I'm at home at the moment so
> can't show some code. Basically I would start/stop the thread from a button
> 'click' handlers. Inside the Run() method was simply a loop to perform the
> range measurements and sleep for the remainder of the 25ms. This solution
> didn't work because I couldn't update the UI entities from this thread.
> Runnable seems to be the better option for accessing views.
>
> I appreciate that android is not a realtime system but thought that 40Hz
> wouldn't be too difficult to achieve, with the occasional overrun, which
> wouldn't impair my app. I am getting nowhere near this - even when I remove
> the range measurement functionality from the run method.
>
> I'll investigate both the timer and scheduledThreadPoolExecutor.
>
> Thanks again.
>
> Marc
>
--
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