简体   繁体   中英

How big and consistent is the delay between touching the display and the call to onTouchEvent in Android?

For my bachelor thesis, I need to write an Android app that gets very exact and consistent reaction times (every millisecond matters) from the user. It will be used for psychological studies. I am using the Android SDK and Java.

One of the ways the user can "react" is by touching the display.

At the moment, I call System.nanoTime() in the onTouchEvent(event) callback. I substract from it the start value (aso taken with System.nanoTime() ) to get the reaction time.

But I am concerned about how fast, exact and consistent (over time / on different devices) the system calls this method after the user actually touched the display.

Possible problems I have in mind:
a) different delays on different devices because of the different hardware used
b) delays because of other threads who could be executed first
c) the high-level nature of the Java language --> you never really know (and can't control) what is happening in the background at what time/order.

How could I find out about this? Could using the NDK(C++) help me get more accurate and consistent values? Thanks!

I need to write an Android app that gets very exact and consistent reaction times (every millisecond matters) from the user

Android is not a real-time operating system (RTOS).

Possible problems I have in mind

Your first two are valid. The third isn't, strictly speaking, in that Java has no more "happening in the background" stuff than do other programming languages. However, Java is intrinsically slower, adding latency.

In most situations, you also need to take into account other apps that may be running, as they too will want CPU time, and there are only so many CPU cores to go around.

How could I find out about this?

You aren't going to have a great way to measure this with a human participant. After all, if you knew exactly when the user touched the screen (to measure the time between it an onTouchEvent() ), you would just use that mechanism instead of onTouchEvent() .

It is possible to create a non-human participant. There are people who have created robots that use a capacitive stylus to tap on the screen. In theory, if you have nicely synchronized clocks, you could determine the time when the robot tapped the screen and the time that you receive the onTouchEvent() call. Having "nicely synchronized clocks" may be difficult in its own right, and creating a screen-touching robot is its own engineering exercise.

Could using the NDK(C++) help me get more accurate and consistent values?

I don't know how you are defining "accurate" in this scenario. I would not expect the NDK to help with consistency. It should help minimize the latency between the screen touch and your finding out about that screen touch (using whatever NDK-based facilities that game developers use to find out about screen touches).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM