【问题标题】:Android InputManagerCompat.InputDeviceListener custom class not receiving callback on any methodAndroid InputManagerCompat.InputDeviceListener 自定义类没有收到任何方法的回调
【发布时间】:2018-08-13 18:32:07
【问题描述】:

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

@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 时,有时 Gamepad 会在 android 中被捕获,并且我的自定义方法 onGenericMotionEventonKeyUp 会被调用。

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

我观察到的事情:

  • 无论如何,当我运行应用程序时,我的方法需要一些时间 被调用,就像我应该强制执行一些延迟加载一样 早点(也许)。
  • 我的更改所基于的代码确实有效,但我介绍了 其他看起来完全不相关的东西(其他类、线程)
  • Lo​​gCat 中没有异常或错误,已经确保没有空捕获和类似的东西

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

提前致谢

【问题讨论】:

    标签: android gamepad


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多