If i'm not mistaken, TimerTasks run on a thread encapsulated in a
Timer object.
Since you can't reliably call most (if not all) UI/View related
methods from any other thread than the main gui-thread, you have to
post back (using a handler) back to the main gui-thread.
I've never tried this using TimerTask, but it may work :=) :
- Create your TimerTask subclass that has access to Handler or to your
View.
- In the 'public void run' method, call post on this handler or view
to do what you want.
@Override
protected void onCreate(Bundle b) {
...
...
final Handler handler = new Handler();
final Runnable doUpdateView = new Runnable() {
public void run() {
... do something with your view ...
}
}
TimerTask myTimerTask = new TimerTask() {
public void run() {
handler.post(doUpdateView);
}
}
...
mTimer.scheduleAtFixedRate(myTimerTask, 0, 1000);
...
}
On May 21, 10:38 am, Mooncat <[email protected]> wrote:
> Is it a no-no to try to update a View from a TimerTask? My initial
> experiments indicate it doesn't work. Is there a way to make it work?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---