The stutter, from what I've picked up on other threads, is as Mark said, due to various other tasks, apps, and more likely garbage collection kicking in randomly. One thing that seems to be a common thread for most "real-time" like UI updating games is to do some sort of time based setup. I forget the details, but basically on each iteration, you figure out the current time, subtract the last "time" that was stored, that tells you how much elapsed time has passed. You use this value to adjust all your UI elements so that rather than seeing a hiccup with the UI, they UI elements themselves "speed up" at various times. Or..maybe speed up isn't the right word. But lets say you have a UI element moving from left to right, 1 pixel per second. A GC hits and causes a 3 second delay. Your UI element hasn't moved for 3 seconds. In the time based method, you would instead move the UI element 3 pixels so that it would be where it should be. The hiccup would still be noticeable.. but at least your UI elements will be where they should be, rather than lagging behind where they should be causing more problems.
There are some threads, and Robert Green and some others have info on here on how to do it. I've yet to really figure out how to apply the difference between two frames time stamps and apply it to the world-coordinate system of a View, for example to make sure a UI element moves to the right position. If you are making a sort of game, one of the other important things to do is do NO creation of objects in the loop. Do all pre-allocation of elements, objects etc before your loop starts.. or between levels, etc. That makes game levels generally small in size based on the very limited 16MB ram (or is it 24MB) you can use for game + images + code... but at least if you can avoid any sort of object allocation/deallocation during the loop, you can put off the GC process longer. At least for your game. There was a thread that was pretty deep on the issue of background services running that could also trigger a GC and cause your game to hiccup.. and the general solution to come of that was Google needs to make some sort of "real-time" game mode so that games that we see on iPhone will be possible on Android. Right now there seems to be no way to guarantee smooth real-time-ish games on Android. Some do a very good job tho. On Sat, Mar 27, 2010 at 4:00 AM, Mark Murphy <[email protected]>wrote: > Neilz wrote: > > Is there a way, to have View elements (TextView, Button, whatever) > > that are not run on the main UI thread? > > No. > > > 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? > > Neither. Your application will crash. > > You cannot modify the widget-based UI from a background thread. > > Now, I cannot speak for 2D (Canvas) or 3D (OpenGL) apps and what their > limitations are vis a vis threads. I am only talking about using Views. > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://twitter.com/commonsguy > > _Android Programming Tutorials_ Version 2.0 Available! > > -- > 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]<android-developers%[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. > -- 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.

