Update:: Robert started a thread on the platform group and filed a bug.. Please consider visiting both sites and star the issues. It’s the only way to get a little bit of attention.
Yes, touch event floods are still there in Android 2.0.1 and according to Robert from Battery Powered Games also in 2.1. He verified this with a rooted devices on which i run top to see what the CPU usage was like when touching and not touching the screen. A thread on the mailing list is also available.
Seeing how this really bugs the hell out of Robert i wrote a small program with libgdx that sets up a GLSurfaceView and outputs the frames per second along with the CPU usage. I artificially throttle the rendering thread to 5 frames per second so that the average CPU usage without touching the screen is low. I tracked the CPU usage by polling /proc/stat which is directly accessible via a FileInputStream. Here’s the code:
package com.badlogic.touchflood;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class CPULoad
{
long total = 0;
long idle = 0;
float usage = 0;
public CPULoad( )
{
readUsage( );
}
public float getUsage( )
{
readUsage( );
return usage;
}
private void readUsage( )
{
try
{
BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( "/proc/stat" ) ), 1000 );
String load = reader.readLine();
reader.close();
String[] toks = load.split(" ");
long currTotal = Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4]);
long currIdle = Long.parseLong(toks[5]);
this.usage = (currTotal - total) * 100.0f / (currTotal - total + currIdle - idle);
this.total = currTotal;
this.idle = currIdle;
}
catch( IOException ex )
{
ex.printStackTrace();
}
}
}
Not to fancy and probably not the best way to do it, however i don’t want to root my phone so that must do
.
Here’s the results for my Milestone with 2.0.1:
- 8-9% CPU usage without touching
- 22%-55% CPU usage with touching
Robert hunted that behaviour down to the KeyInputQueue, an Android framework class implemented on the Java side of things. The processing of new events, be it keyboard or touch events is implemented without any performance considerations appearantly. No amount of sleeping will be able to solve that problem, so what that guy who did Replica Island said in his Google I/O talk is not correct.
Note that the above results are for Android 2.0.1 on my Milestone. On older chips as well as Android versions this will be a lot worse. I will try it on my Hero tomorrow once i get a hold of it (Stefanie is the proud owner of it at the moment).
For me as a hobbyist it’s just a bit of an annoyance but i don’t know whether there’s a reason that the Android team hasn’t decided yet to fix it. However, for people like Robert that try to make a living of Android game dev it is indeed a big problem. Bad performance is directly reflected by bad user comments which in turn has an impact on your downloads and sales.
On a related note: i tried out Zenonia today, a nice little Zelda clone. The description says it does support multitouch. Coming from a big name (Gamevil) i thought they for sure must have figured out a way around the intrinsic multitouch bug(s) on Android. Well, turns out they didn’t. If you go to the left via the onscreen d-pad and press the action button while holding down the onscree d-pad movement stops. Oh well, at least we small devs aren’t just to stupid
You can find an apk of the touch flood test at http://www.file-pasta.com/file/1/touchflood.apk, the Eclipse project can be downloaded from http://www.file-pasta.com/file/0/touchflood.zip