Search code examples
androidandroid-input-method

weird Logcat output when dismissing custom keyboard


I am have a custom keyboard app, and I get this LogCat output about 1/4 of the time when I press the back button to get out of it:

12-19 13:18:13.908: W/InputMethodManager(361): IME died: com.mypackage/.MyActivity dropping: KeyEvent{action=1 code=4 repeat=0 meta=0 scancode=158 mFlags=72}
12-19 13:18:13.908: W/InputMethodManager(361): android.os.DeadObjectException
12-19 13:18:13.908: W/InputMethodManager(361):  at android.os.BinderProxy.transact(Native Method)
12-19 13:18:13.908: W/InputMethodManager(361):  at com.android.internal.view.IInputMethodSession$Stub$Proxy.dispatchKeyEvent(IInputMethodSession.java:277)
12-19 13:18:13.908: W/InputMethodManager(361):  at android.view.inputmethod.InputMethodManager.dispatchKeyEvent(InputMethodManager.java:1344)
12-19 13:18:13.908: W/InputMethodManager(361):  at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:2426)
12-19 13:18:13.908: W/InputMethodManager(361):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1741)
12-19 13:18:13.908: W/InputMethodManager(361):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-19 13:18:13.908: W/InputMethodManager(361):  at android.os.Looper.loop(Looper.java:123)
12-19 13:18:13.908: W/InputMethodManager(361):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-19 13:18:13.908: W/InputMethodManager(361):  at java.lang.reflect.Method.invokeNative(Native Method)
12-19 13:18:13.908: W/InputMethodManager(361):  at java.lang.reflect.Method.invoke(Method.java:521)
12-19 13:18:13.908: W/InputMethodManager(361):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-19 13:18:13.908: W/InputMethodManager(361):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-19 13:18:13.908: W/InputMethodManager(361):  at dalvik.system.NativeStart.main(Native Method)

Has anyone encountered this before?

Here is the code I have when overriding the back button

if(mInputView.getVisibility() == View.VISIBLE){

    if(isInputViewShown()){
        if(output != null){
             if(getCurrentInputConnection() != null){
                       getCurrentInputConnection().deleteSurroundingText(1000, 1000);
                       getCurrentInputConnection().commitText(output.getText(), output.length());
             }
        output.setText("");
    }

    requestHideSelf(0);
    return true;
}else return false;

Solution

  • It looks like you're getting a race condition between cancelling the keyboard, and dispatching the keyevent that was generated by pressing the back button. The DeadObjectException means that although the object (here the KeyEvent) is still in use, its host process (the IME) has died. This invalidates the object and throws the exception.

    You can see this in the KeyEvent parameters. The key code is 4, which is the value of KeyEvent.KEYCODE_BACK.

    Different phones probably behave different ways here (this unanswered question is similar). I would guess the exception can be ignored.