views:

392

answers:

3

I have written a very simple game with some simple animations, but I've noticed that when the phone checks email, or several other apps are running, the animations that update in my thread start behaving slowly or choppy.

This is a problem as the game mechanic requires some careful timing of your screen touches based on the animations. So if it starts behaving erratically, the game doesn't really work well - and isn't much fun.

Is there a way to prevent this? Can my threads have a higher priority when they need to run?

A: 

If you are switching to the phone / or some other app while running your game, stop your game thread. Check for basics, such as wasteful 'newing' of stuff, unnecessary stuff. As last fix you might want to perform some drawing with a GL context.

Hope this helps :)

Karol Wilk
Well, the game runs normally most of the time, but then sometimes, when the phone starts doing something else, the drawing slows down, probably because the phone is busy doing something else.
Ben Mc
+1  A: 

Try setting the thread priority to maximum. This can make a big difference on the performance of a rendering thread in android:

mThread.setPriority(Thread.MAX_PRIORITY)
Ralphleon
A: 

From what I've seen in the Android source code this seems to be the preferred way to change thread priority, unfortunately I can't find much documentation about this versus using the Thread class:

Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_DISPLAY);
satur9nine