Why does my custom soft keyboard not open after rebooting the device?

I developed a special soft keyboard based on the sample Android soft keyboard.

The problem that I encountered is restarting the device and clicking on EditText in the Android environment, my keyboard is not displayed, and I need to go to the Android login settings, change the default keyboard and select my keyboard again. After that, when I click on EditText, my keyboard is displayed and everything is fine until the next device reboots.

What could be the source of this error?

manifest:

<application android:label="@string/ime_name" >
    <service
        android:name="com.test.softkeyboard.SoftKeyboard"
        android:permission="android.permission.BIND_INPUT_METHOD" >
        <intent-filter >
            <action android:name="android.view.InputMethod" />
        </intent-filter>

        <meta-data
            android:name="android.view.im"
            android:resource="@xml/method" />
    </service>
</application>

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true" />

Some of my methods are:

@Override
    public void onCreate() {
        super.onCreate();
        mWordSeparators = getResources().getString(R.string.word_separators);
    }


@Override
    public View onCreateCandidatesView() {
        mCandidateView = new CandidateView(this);
        mCandidateView.setService(this);
        return mCandidateView;
        // return null;
    }



@Override
    public View onCreateInputView() {
        mInputView = (KeyboardView) getLayoutInflater().inflate(
                R.layout.input, null);
        mInputView.setOnKeyboardActionListener(this);
        mInputView.setKeyboard(loadState());
        return mInputView;
    }


@Override
    public void onDisplayCompletions(CompletionInfo[] completions) {
        if (mCompletionOn) {
            mCompletions = completions;
            if (completions == null) {
                setSuggestions(null, false, false);
                return;
            }

            List<String> stringList = new ArrayList<String>();
            for (int i = 0; i < (completions != null ? completions.length : 0); i++) {
                CompletionInfo ci = completions[i];
                if (ci != null)
                    stringList.add(ci.getText().toString());
            }
            setSuggestions(stringList, true, true);
        }
    }




@Override
    public void onFinishInput() {
        super.onFinishInput();

        // Clear current composing text and candidates.
        mComposing.setLength(0);
        updateCandidates();

        // We only hide the candidates window when finishing input on
        // a particular editor, to avoid popping the underlying application
        // up and down if the user is entering text into the bottom of
        // its window.
        setCandidatesViewShown(false);

        saveState(mCurKeyboard);
        // mCurKeyboard = mQwertyKeyboard_Fa;
        if (mInputView != null) {
            mInputView.closing();
        }
    }


@Override
    public void onInitializeInterface() {
        if (mQwertyKeyboard_Fa != null) {
            // Configuration changes can happen after the keyboard gets
            // recreated,
            // so we need to be able to re-build the keyboards if the available
            // space has changed.
            int displayWidth = getMaxWidth();
            if (displayWidth == mLastDisplayWidth)
                return;
            mLastDisplayWidth = displayWidth;
        }

        mQwertyKeyboard_Fa = new LatinKeyboard(this, R.xml.qwerty_fa);
        mQwertyKeyboard_En = new LatinKeyboard(this, R.xml.qwerty_en);
        mSymbolsKeyboard = new LatinKeyboard(this, R.xml.symbols);
        mSymbolsShiftedKeyboard = new LatinKeyboard(this, R.xml.symbols_shift);
        mSymbolsSimpleKeyboard = new LatinKeyboard(this, R.xml.symbols_simple);
    }



@Override
    public void onStartInputView(EditorInfo attribute, boolean restarting) {
        super.onStartInputView(attribute, restarting);
        // Apply the selected keyboard to the input view.
        mInputView.setKeyboard(mCurKeyboard);
        mInputView.closing();

    }
+4

Source: https://habr.com/ru/post/1612390/


All Articles