Ok, reviving an older thread.

Is there a way, to have View elements (TextView, Button, whatever)
that are not run on the main UI thread?

What about if I set up a game thread, with its own View (like in the
LunarLander sample, for instance) and then create View elements on the
fly and attach them to the main View? Are these still going to be run
in the main UI thread, or in the game thread?

Thanks.

On Mar 4, 4:20 pm, Mark Murphy <[email protected]> wrote:
> Neilzwrote:
> > Hi all. I have an activity that uses a Timer (java.util.Timer) to
> > control the display. I set it off to repeat its run() method every
> > second or so. When it runs, it updates some View elements.
>
> > As Timer runs in its own thread, I assumed this would be reliable. But
> > I notice that sometimes there is a stutter, or delay, in the views
> > updating. It's like they occasionally get stacked up, and all happen
> > together. Studying the output from logcat, I notice that this happens
> > when the device is doing something else - some system functions, or
> > sometimes a garbage collection.
>
> > How can I avoid this?
>
> You can't.
>
> > I'm not aware I can run the main activity in a
> > thread of its own, can I? If the timer has its own thread, why is it
> > affected?
>
> Because the UI is drawn on the main application thread.
>
> Whenever you make a change to the UI -- such as calling setText() on a
> TextView -- think of it as putting a message on a message queue that is
> processed in a message loop by the main application thread.
>
> All your Timer is doing is triggering some messages to go into that
> queue on a periodic basis. How quickly those messages will be popped off
> the queue and processed depends on what else is in the queue, how much
> time those other things in the queue take (including time in your
> activity and listener callback methods), what else is being done in
> threads in your application, and what else is being done in other
> processes on the device.
>
> You can simplify your current implementation by dumping the Timer and
> using postDelayed() to trigger your updates, for what that's worth.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Training:http://commonsware.com/training

-- 
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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to