gpt4 book ai didi

android - InputMethodService 中有两个 InputConnection 变量?

转载 作者:太空狗 更新时间:2023-10-29 15:02:17 26 4
gpt4 key购买 nike

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

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

mCurrentInputConnection == Ime.getCurrentInputConnection()

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

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

最佳答案

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

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

关于android - InputMethodService 中有两个 InputConnection 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25479807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com