Android. Touch = Half FPS

Premise: My phone is a weak LG e720, which has a slow single core processor, angry birds space runs like 5 FPS on it, previous angry birds was fine.
Using libgdx.

In my Android game, whenever I hold down the finger on the screen, on my device - I have not seen it yet on other devices, my FPS halfs.
Runs on a solid 60 FPS, but holding down the finger just halfs it.
It’s not really what happens due to finger down; because what happens is scrolling. However automatically scrolling runs 60 fps. Mere holding down and not moving results in 30 FPS.

Using DDMS I couldn’t really profile it, I just didn’t understand it really.

Also, running it on PC without Vsync, the FPS are exactly the same when holding down or not: ~ 2000fps on my machine

Another interesting thing is, I have witnessed this before: When I installed a NES or SNES emulator, whenever I would hold a button down, the game would dramatically slow down, but only then.

You guys got any ideas, besides “well, it’s a slow phone” - since I do want the game of course to run on slow phones.

I think it’s using the CPU to process the finger tracking stuff in the OS, and it would seem to be using rather a lot of it.

Cas :slight_smile:

There was an issue with android on older version of the OS (supposed to be older than 2.0 but there are reports of people with the problem on newer versions, like 2.1 and 2.2) the problem is that the native side of the android os floods the android application with touch events, and that is why you see the game slow down, the touch handling is taking a lot of your cpu.

In newer versions this is patched and is not an issue, but on older versions the recommended fix (not a total/real fix but at least it makes it better) is to add a sleep() call in your input handling method to keep the native code from calling the input handler so much.

Since you are using libgdx you can use the class com.badlogic.gdx.backends.android.AndroidApplicationConfiguration when you create your android app and set the parameter touchSleepTime on it to 16 like it is recommended in the javadocs for the class.

hope it helps, and I would love to know if it does fix it for you, and what version of the android OS you have.

Rubén

EDIT: this is an issue about this on the android project - http://code.google.com/p/android/issues/detail?id=7836

Ah nice, I didn’t notice that.

Well 40 FPS instead of 30 FPS.
Android 2.2.1

That’s pretty much as good as it gets. I originally started working on a HTC Hero in 2009, had the same issues. There’s no fix i’m afraid. 40fps is plenty though. Welcome to Android :confused: