Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are touch events destroying my Android framerate?

I'm developing a game for Android. It's got a lot going on but is running reasonably smoothly. That is, of course, until the user touches the screen.

While they're touching it, onTouchEvent is called (with action = ACTION_MOVE, x = 0 and y = 0) roughly once every ten milliseconds at what appears to be a fairly high priority, as it absolutely obliterates the framerate. As soon as the touch ends the framerate returns to its nice state.

I've tried

  • having onTouchEvent handle input for the game as usual
  • having onTouchEvent return true straight away
  • not having onTouchEvent implemented at all

The problem persists in all three situations.

Has anyone encountered this? Is there a way to reduce the rate at which ACTION_MOVE events are generated, or to ensure that they're only generated when there is actual movement, or use a polling method that just gets the current location of the touch? Or even just a way to disable it entirely?

like image 935
mcccclean Avatar asked Apr 27 '09 03:04

mcccclean


1 Answers

Read this thread. Basically you want to sleep the event thread since otherwise the system will pump a lot of events (between x,y and pressure there is always some movement going on) that you need to handle.

like image 96
hacken Avatar answered Sep 23 '22 02:09

hacken