Android InputManagerCompat.InputDeviceListener 自定义 class 没有收到任何方法的回调

Android InputManagerCompat.InputDeviceListener custom class not receiving callback on any method

我有一个 Android 应用程序,它使用 class 扩展以下类型:

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public class GamePadController extends View implements InputManagerCompat.InputDeviceListener {
    // The current device that is controlling the ship
    private InputDevice mInputDevice;
    private int mDPadState;
    ...

当我 运行 手机中的 apk 有时会在 android 中捕获游戏手柄并调用我的自定义方法 onGenericMotionEventonKeyUp

这是一种随机行为,有时会调用我的方法并执行我的行为,但有时只会发生默认行为(比如我的 classes 没有注册)。

我观察到的事情:

你对这种行为有什么线索或建议吗?

提前致谢

所以我似乎将回调方法放在 Activity 中的特定视图中(它有其他元素,如 textviews),这意味着只有当特定元素被聚焦时,输入才会被捕获回调...这就是文档告诉您将回调放在 Activity 或视图中的原因...可能将此行为放在 activity 中更有意义,因此无论如何它都会被捕获重点是什么。