1

我有一个非常简单的 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我只在调用时单击了文本输入。当在屏幕之间导航时,它会在onBindonStartInput、之间循环onUnbind。我错过了什么吗?

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");
    }
}
4

2 回答 2

1

我已经删除了所有被覆盖的方法,只留下了onCreateInputView它现在被调用了,不知道什么不起作用,特别是因为我到处都在调用超类方法......

于 2013-11-13T17:37:21.380 回答
1

尝试更改onShowInputRequested

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

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

于 2015-05-26T06:37:27.267 回答