【问题标题】:Two InputConnection variable in InputMethodService?InputMethodService 中的两个 InputConnection 变量?
【发布时间】:2014-10-18 05:50:24
【问题描述】:

我正在尝试实现自己的 android 输入法。在InputMethodService.onStartInputView 中,我保存了对InputConnection 的引用,该引用由getCurrentInputConnection 返回以供以后使用。在 keyup 事件中,我调用 InputConnection.commitText 将一些文本提交到屏幕上。

但我发现在某些应用程序中,该函数调用无效(即屏幕上什么都没有出现)而
softKeyBoard sdk 示例运行良好。唯一的区别是样本使用getCurrentInputConnect 来提交字符。此外,我的应用程序中的声明是 false

mCurrentInputConnection == Ime.getCurrentInputConnection()

在 IME 服务的source code 中,有两个 InputConnection 成员:mInputConnection 和 mStartedInputConnection,getCurrentInputConnection 可能会返回任何一个。

我知道我每次都可以调用getCurrentInputConnection,但我只是想避免因性能问题而调用函数(因为调用过于频繁)。那么有没有其他方法来获得正确 InputConnection? (两者有什么区别?)

【问题讨论】:

    标签: android android-input-method


    【解决方案1】:

    InputConnection 的单个实例停止工作,因为一旦您打开其他应用程序或更改 editText 字段,新客户端已与您的 IME 绑定,因此输入连接已更改。

    如果您想避免多次调用getCurrentInputConnection(),那么您可以在每次更改时存储一个InputConnection 对象。它的回调是onBindInput

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 2014-10-15
      相关资源
      最近更新 更多