问题
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
回答1:
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.
回答2:
In my case in the button layout I had this: android:textIsSelectable="true"
, just removing it and problem solved...
回答3:
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);
}
}
}
};
回答4:
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
来源:https://stackoverflow.com/questions/12318521/inputconnectionwrapper-warning