Two InputConnection variables in InputMethodService?
I am trying to implement my own android IME. In InputMethodService.onStartInputView
I save the reference to InputConnection
, returned getCurrentInputConnection
for later use. And in the keyup event, I call InputConnection.commitText
to pass the text to the screen.
But I find that in some applications this function call has no effect (nothing appears on the screen) and the softkeyboard sdk sample works well. The only difference is what the sample uses getCurrentInputConnect
to capture the symbols. Also, the expression in my application is false
mCurrentInputConnection == Ime.getCurrentInputConnection()
There are two InputConnection elements in the IME source code, mInputConnection and mStartedInputConnection, and getCurrentInputConnection
can be returned as well.
I know I can call every time getCurrentInputConnection
, but I just want to avoid calling the function for a performance problem (because it will be called too often). So, is there any other approach for getting the correct InputConnection? (and what's the difference between them?)
source to share
Your only instance InputConnection
stops working because as soon as you open some other application or change the editText field, the new client contacted your IME and hence the input connection changed.
If you want to reuse multiple calls getCurrentInputConnection()
, you can store the object InputConnection
every time it changes. The callback for this is onBindInput .
source to share