I’m working on an Android game using these tutorials over at Against the Grain http://obviam.net/index.php/table-of-contents/ and my program has suddenly decided to have an ANR Key Dispatching Timed Out error whenever I touch the screen.
Basically I have a MainMenuThread class that extends thread which has the main game loop in it, simply calling update and render functions in my MainMenuPanel which extends SurfaceView and handles the actual game.
I load in a bunch of images of square buttons which I lerp from the top of the screen to the bottom, after which I display 4 other images that will be buttons and flash the screen (simple lerp and a call to canvas.drawARGB). Once this has finished, when the user presses on one of the squares for the background it changes to an image of a pressed down square, this did work. Initially I hacked in some code that on touch event looped through each and every square in the background, checked if the event coords were on it and reacted accordingly, I’ve now changed this to be much more streamlined but for some reason I keep getting a KeyDispatchingTimedOut every time I touch the screen.
I was running this on my quad core machine at home which emulated it all just fine (before the streamline) I’m now working on my netbook which can’t even run an android virtual device so I’m debugging on my phone (HTC Hero).
I googled around for answers and found people saying that it could be because it is doing too much work so I stopped it drawing the square background and output a message to logcat on each touch event but I still get the same problem, I also tried launching a new thread on each touch event that handled this for me but that didn’t fix it. The only other thing I’ve seen in google searches is people saying that android can spit out this error if the surface no-longer exists but it almost definitely does.
The only other thing I can think to say is that it doesn’t even get into my logic, my code is:
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
Log.d(TAG, "Touch event registered");
int x = (int)event.getX() / squareSize;
int y = (int)(getHeight() - event.getY()) / squareSize;
squares[x][y].setTouched(true);
}
and the “Touch event registered” message is never output.
Thanks in advance for any help that can be offered, and as this is my first question on here I hope that this isn’t too long winded/irrelevant.
It turns out that my phone was faulty >:(