androidkotlinandroid-softkeyboardandroid-input-method

InputMethodService onCreateInputView not called


I have a simple InputMethodService implementation:

class MyKeyboardView : InputMethodService() {

    override fun onCreate() {
        super.onCreate()

        Timber.d("onCreate")
    }

    // Also tried the default implementation
    override fun onShowInputRequested(flags: Int, configChange: Boolean): Boolean {
        Timber.d("onShowInputRequested")

        return true
    }

    override fun onCreateInputView(): View {
        Timber.d("onCreateInputView")

        return KeyboardView(this)
    }

    private class KeyboardView @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
    ) : View(context, attrs, defStyleAttr) {

        init {
            Timber.d("Init")
        }
    }

}

Input method is selected as current one.

Other methods like onCreate, onShowInputRequested, onStartInputView are called, but not onCreateInputView.

onCreateInputView is never called. Why?


Solution

  • From onStartInputView's doc:

    You are guaranteed that onCreateInputView() will have been called some time before this function is called.

    So if you're seeing debug logs from this method, the create method must be called.

    Try to override onEvaluateInputViewShown too and return true.