从未调用过InputMethodService onCreateInputView

时间:2013-11-13 15:38:02

标签: android android-input-method

我有一个非常简单的InputMethodService,我所做的只是记录生命周期的不同阶段。我从未调用onCreateInputView,日志显示奇怪的事情。

  MyInput       D  onCreate
                D  onInitializeInterface
                D  onBindInput
                D  onStartInput
                D  onUnbindInput
                D  onBindInput
                D  onStartInput
                D  onUnbindInput
                D  onBindInput
                D  onStartInput
                D  onShowInputRequested

我在调用onShowInputRequested时只点击了文本输入。在屏幕之间导航时,它会在onBindonStartInputonUnbind之间循环。我错过了什么吗?

public class MyInput extends InputMethodService {
    private static final String TAG = "MyInput";

    private InputMethodManager mInputMethodManager;

    @Override
    public void onCreate() {
        super.onCreate();
        mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        Log.d(TAG, "onCreate");
    }

    @Override
    public void onInitializeInterface() {
        super.onInitializeInterface();
        Log.d(TAG, "onInitializeInterface");
    }

    @Override
    public View onCreateInputView() {
        Log.d(TAG, "onCreateInputView");
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        return inflater.inflate(R.layout.my_keyboard, null);
    }

    @Override
    public void onFinishInput() {
        super.onFinishInput();
        Log.d(TAG, "onFinishInput");
    }

    @Override
    public void onStartInput(EditorInfo attribute, boolean restarting) {
        super.onStartInput(attribute, restarting);
        Log.d(TAG, "onStartInput");
    }

    @Override
    public void onFinishInputView(boolean finishingInput) {
        super.onFinishInputView(finishingInput);
        Log.d(TAG, "onFinishInputView");
    }

    @Override
    public boolean onShowInputRequested(int flags, boolean configChange) {
        Log.d(TAG, "onShowInputRequested");
        return super.onShowInputRequested(flags, configChange);
    }

    @Override
    public void onBindInput() {
        super.onBindInput();
        Log.d(TAG, "onBindInput");
    }

    @Override
    public void onUnbindInput() {
        super.onUnbindInput();
        Log.d(TAG, "onUnbindInput");
    }

    @Override
    public void onStartInputView(EditorInfo attribute, boolean restarting) {
        super.onStartInputView(attribute, restarting);
        Log.d(TAG, "onStartInputView restarting = " + restarting);
    }

    @Override
    public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
        Log.d(TAG, "onCurrentInputMethodSubtypeChanged");
    }
}

2 个答案:

答案 0 :(得分:1)

我删除了所有重写的方法,只留下onCreateInputView,现在调用它,不知道什么不起作用,特别是因为我在所有地方调用超类方法......

答案 1 :(得分:1)

尝试更改onShowInputRequested

@Override
public boolean onShowInputRequested(int flags, boolean configChange) {
    return true;
}

我的情况大致相同,在某些情况下我的键盘没有显示,这对我很有帮助。