Jack wrote: > Right now my test program uses a very simple method: I have a handler > that is called to start the animation. The handler's handleMessage() > method calculates the new frame, invalidates the view, and calls > sendMessageDelayed(obtainMessage(0), 50); > > However, the animation isn't smooth - especially, for some reason, in > landscape mode. Portrait mode seems much better (on a G1, if it > matters).
That is to be expected. > This suggests to me that this isn't the right way to... handle... this > problem. What would be a better way? You can think of the main application ("UI") thread as being a message loop driven by a message queue. Whenever you call setText() or invalidate() or whatever, you are really putting a message on that queue. That queue's messages are processed whenever Android isn't executing your code (e.g., callbacks like onCreate() or onClick() or handleMessage()). What your sendMessageDelayed() is doing is putting a message on the queue with a time associated with it. Android will ignore that message, even if it is at the head of the queue, until that time elapses. However, just because the time has elapsed does not mean that it will get executed immediately, because Android may have moved on to other messages, or be in your code, or whatever. Hence, sendMessageDelayed() or postDelayed() or kin will result in some degree of choppiness, depending on what else is going on. This is a chunk of the reason for AnimationDrawable and the Animation classes -- they will give you smooth animations. > Starting > a new thread whenever the animation starts and having it repeatedly > calculate and invalidate instead of relying on the handler, even > though it means creating and destroying a new thread every time? That wouldn't help, because you cannot update the UI from the background thread. All the background thread will do is wind up telling the UI thread, via a message on the queue, to go do something. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in US: 14-18 June 2010: http://bignerdranch.com -- 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