Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getExtractedText on inactive InputConnection warning on android

I get the following warning in my logcat.

getExtractedText on inactive InputConnection 

I'm unable to find the reason behind it. Please help

like image 906
pankajagarwal Avatar asked Nov 14 '11 13:11

pankajagarwal


1 Answers

I ran into a similar issue. My logcat:

W/IInputConnectionWrapper(21214): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper(21214): getSelectedText on inactive InputConnection W/IInputConnectionWrapper(21214): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper(21214): getTextAfterCursor on inactive InputConnection ... I/Choreographer(20010): Skipped 30 frames!  The application may be doing too much work on its main thread. 

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

Ex:

editText.setText(null); 

The last line in my logcat above provides a great indication of what is happening. Sure enough, the InputConnection is overwhelmed by 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()); } 
like image 197
Johnson Wong Avatar answered Oct 05 '22 14:10

Johnson Wong