7

On Android, is there a way of adjusting the touch input sample rate?

Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93

2 Answers2

5

You can't stop the system generating these events however you can selectively ignore some of the ACTION_MOVE events as you will see up to 60 per second each reporting the same co-ordinates.

You may wish to only process these ACTION_MOVE events after a set time since the last event, or skip to every 5th or 10th event etc. You'll have to experiment and see what works best for you.

Just make sure you don't skip ACTION_UP or your application may get into a confused state with the touches.

Tyler
  • 19,113
  • 19
  • 94
  • 151
ScouseChris
  • 4,377
  • 32
  • 38
0

I'm supposing you're trying to adjust the rate as you dealing within onTouch function.

    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction()){
              case MotionEvent.ACTION_DOWN:
                  downTime = event.getDownTime();
                  // Do something you want to.
                  break;
              case MotionEvent.ACTION_MOVE:
              case MotionEvent.ACTION_UP:
                  eventTime = event.getEventTime();
                  if(eventTime - downTime > 25){
                       // Do something you want to.
                  }
                  break;
        }
    }

You should declare long variable downTime and eventTime in your class. Also the unit of them is ms. Hope that will help you out.

2011/7/20 Maybe you can try:

    Tread.sleep(time);

See if it helps.

Desolve
  • 23
  • 6