简体   繁体   English

Android 中触摸显示器和调用 onTouchEvent 之间的延迟有多大和一致性?

[英]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.对于我的学士论文,我需要编写一个 Android 应用程序,从用户那里获得非常精确和一致的反应时间(每一毫秒都很重要)。 It will be used for psychological studies.它将用于心理学研究。 I am using the Android SDK and Java.我正在使用 Android SDK 和 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.目前,我在onTouchEvent(event)回调中调用System.nanoTime() I substract from it the start value (aso taken with System.nanoTime() ) to get the reaction time.我从中减去起始值(与System.nanoTime() 一起使用)以获得反应时间。

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 a) 由于使用的硬件不同,不同设备上的延迟不同
b) delays because of other threads who could be executed first b) 由于其他线程可以先执行而导致的延迟
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. c) Java 语言的高级特性 --> 您永远不会真正知道(也无法控制)后台在什么时间/顺序发生了什么。

How could I find out about this?我怎么知道这件事? Could using the NDK(C++) help me get more accurate and consistent values?使用 NDK(C++) 可以帮助我获得更准确和一致的值吗? Thanks!谢谢!

I need to write an Android app that gets very exact and consistent reaction times (every millisecond matters) from the user我需要编写一个 Android 应用程序,从用户那里获得非常精确和一致的反应时间(每一毫秒都很重要)

Android is not a real-time operating system (RTOS). Android 不是实时操作系统 (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.严格来说,第三个不是,因为 Java 没有比其他编程语言更多的“在后台发生”的东西。 However, Java is intrinsically slower, adding latency.但是,Java 本质上更慢,会增加延迟。

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.在大多数情况下,您还需要考虑可能正在运行的其他应用程序,因为它们也需要 CPU 时间,并且只有这么多 CPU 内核可以运行。

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() .毕竟,如果您确切地知道用户何时触摸屏幕(以测量它与onTouchEvent()之间的时间),您只需使用该机制而不是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.理论上,如果您有很好的同步时钟,您可以确定机器人点击屏幕的时间以及您收到onTouchEvent()调用的时间。 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?使用 NDK(C++) 可以帮助我获得更准确和一致的值吗?

I don't know how you are defining "accurate" in this scenario.我不知道您在这种情况下如何定义“准确”。 I would not expect the NDK to help with consistency.我不希望 NDK 有助于保持一致性。 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).它应该有助于最大限度地减少屏幕触摸和您发现屏幕触摸之间的延迟(使用游戏开发人员用来查找屏幕触摸的任何基于 NDK 的工具)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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