Ben Mc
Ben Mc

Reputation: 2078

Android thread problems due to background processes

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?

Upvotes: 3

Views: 3382

Answers (3)

satur9nine
satur9nine

Reputation: 15092

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

Upvotes: 2

Ralphleon
Ralphleon

Reputation: 4118

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)

Upvotes: 3

bgs
bgs

Reputation: 1250

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

Upvotes: 0

Related Questions