12

I get an InputConnectionWrapper warning everytime I turn off the screen when my app is visible. I don't know why, because I don't use InputConnection.

Here is the LogCat Output.

09-07 14:21:31.716: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:31.724: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:31.724: W/IInputConnectionWrapper(24197): getTextBeforeCursor on inactive InputConnection
09-07 14:21:31.724: W/IInputConnectionWrapper(24197): getTextAfterCursor on inactive InputConnection
09-07 14:21:31.724: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:31.724: W/IInputConnectionWrapper(24197): getTextBeforeCursor on inactive InputConnection
09-07 14:21:31.724: W/IInputConnectionWrapper(24197): getTextAfterCursor on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): beginBatchEdit on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): endBatchEdit on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): getTextBeforeCursor on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): getTextAfterCursor on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): beginBatchEdit on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): endBatchEdit on inactive InputConnection
09-07 14:21:31.732: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:32.013: W/IInputConnectionWrapper(24197): showStatusIcon on inactive InputConnection
09-07 14:21:32.013: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getTextBeforeCursor on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getTextAfterCursor on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getTextBeforeCursor on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getTextAfterCursor on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): beginBatchEdit on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): endBatchEdit on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getTextBeforeCursor on inactive InputConnection
09-07 14:21:32.021: W/IInputConnectionWrapper(24197): getTextAfterCursor on inactive InputConnection
09-07 14:21:32.028: W/IInputConnectionWrapper(24197): beginBatchEdit on inactive InputConnection
09-07 14:21:32.028: W/IInputConnectionWrapper(24197): endBatchEdit on inactive InputConnection
09-07 14:21:32.028: W/IInputConnectionWrapper(24197): getExtractedText on inactive InputConnection
Lane
  • 2,669
  • 3
  • 25
  • 38
Leandros
  • 16,805
  • 9
  • 69
  • 108

5 Answers5

0

guess already too late to help but it is in my case the problem that I have a "setOnEditorActionListener" on an text edit -- if I remove this listener the warning is gone.

Paul
  • 193
  • 1
  • 8
0

In my case in the button layout I had this: android:textIsSelectable="true", just removing it and problem solved...

KronuZ
  • 378
  • 2
  • 13
0
TextWatcher textWatcherContent = new TextWatcher() {

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        String content = mTxtContent.getText().toString();
        String contact = mTxtContact.getText().toString();
        if (null != mTxtContent && null != mTxtLength) {
            int length = mTxtContent.getText().toString().length();

            if (length > 200) {

                mTxtContent.removeTextChangedListener(textWatcherContent);
                SpannableString spannableString = new SpannableString(content);

                spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF3838")), 200
                            , mTxtContent.length() , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                mTxtContent.getText().clear();
                mTxtContent.append(spannableString);
                mTxtContent.setSelection(content.length());

                mTxtContent.addTextChangedListener(textWatcherContent);
            }          
        }
    }
};
barbsan
  • 3,418
  • 11
  • 21
  • 28
  • user code : mTxtContent.removeTextChangedListener(textWatcherContent); and mTxtContent.addTextChangedListener(textWatcherContent); – lang chen Jul 11 '19 at 08:49
  • 2
    Welcome to Stack Overflow. While your code may provide the answer to the question, please add context around it so others will have some idea what it does and why it is there. – Theo Jul 11 '19 at 08:52
  • I have absolutely no idea how in the world this answers the OP's question. – Pete Alvin Feb 22 '20 at 20:18
0

I am using a webView to browse a URL of which I am required to either sign-up or log in. My app just froze when I switched focus to a different TextField and I got the same errors above.

How I manage to resolve it is that it was missing this crucial piece of code below:

@override
void initState() {
  super.initState();
  if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}

This code should lie after the declaration of the instance class that extends the main class and before the build Widget function.

In the error logs you might still see the same warnings but it will definitely resolve whatever issues were being caused, whether it was the Swift keyboard or the TextFields themselves.

David Buck
  • 3,752
  • 35
  • 31
  • 35
-7

It turned out that the above usage of the InputConnectionWrapper was totally correct. However, commitText() gets never called (except for special cases), as there are other methods, which are used during typing. These are mainly setComposingText() and sendKeyEvent().

However, it is also important to override seldom used methods like deleteSurroundingText() or commitText() to make sure to catch every user input, because I ran into a similar issue.

My situation: I have an EditText view the user types into. The EditText gets cleared when the user presses a button. Lots of inactive InputConnection entries stream out when I rapidly press the button.

E.g. editText.setText(null);

The last line in my logcat above provides a great indication of what is happening. Sure enough, the InputConnection is overwhelmed with requests to clear the text. I tried modifying the code to check for text length before trying to clear it:

if (editText.length() > 0) {
    editText.setText(null);
}

This helps mitigate the problem in that pressing the button rapidly no longer causes the stream of IInputConnectionWrapper warnings. However this is still prone to problems when the user rapidly alternates between typing something and pressing the button or presses the button when the app is under sufficient load, etc.

Fortunately, I found another way to clear text: Editable.clear(). With this I don't get warnings at all:

if (editText.length() > 0) {
    editText.getText().clear();
}

Note that should you wish to clear all input state and not just the text (autotext, autocap, multitap, undo), you can use TextKeyListener.clear(Editable e).

if (editText.length() > 0) {
    TextKeyListener.clear(editText.getText());
}

If you want to know more about input connection wrapper please visit the link below.

http://developer.android.com/reference/android/view/inputmethod/InputConnection.html

Indivara
  • 735
  • 1
  • 7
  • 19
Sethu
  • 430
  • 2
  • 13
  • 16
    it appears that you copied nearly verbatim Johnson Wong's answer at http://stackoverflow.com/questions/8122625/getextractedtext-on-inactive-inputconnection-warning-on-android – Michael Chinen Oct 21 '14 at 02:23