On Android, is there a way of adjusting the touch input sample rate?
Asked
Active
Viewed 3,223 times
2 Answers
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
-
No, I am trying to adjust the actual rate MotionEvents are generated. Even without an onTouch method, the frame rate drops when I touch the screen. – Christian Neverdal Jul 19 '11 at 12:19
-
Yes, and I am trying to reduce the number of MotionEvents. – Christian Neverdal Jul 21 '11 at 21:08
-
Thread.sleep(time) is no good either, everything just slows down. – Christian Neverdal Jul 21 '11 at 21:15