我碰到了一个类似的问题。我的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.
我的情况:
我有一个EditText视图用户类型。当用户按下按钮时,EditText被清除。当我快速按下按钮时,很多非活动的InputConnection条目流出。
例如:
editText.setText(null);
我的logcat中的最后一行提供了一个很好的指示,正在发生什么。果然,InputConnection被清除文本的请求所淹没。我试图修改代码以检查文本长度,然后再尝试清除它:
if (editText.length() > 0) {
editText.setText(null);
}
这有助于缓解快速按下按钮不再导致IInputConnectionWrapper警告流的问题。然而,当用户在键入东西和按下按钮之间快速交替时,或者当应用程序处于充分负载等时按下按钮,这仍然容易出现问题。
幸运的是,我发现了另一种方式来清除文本:Editable.clear().有了这一点,我不会得到警告:
if (editText.length() > 0) {
editText.getText().clear();
}
注意,如果你想清除所有的输入状态,而不只是文本(自动文本,autocap,multitap,撤消),你可以使用TextKeyListener.clear(Editable e)。
if (editText.length() > 0) {
TextKeyListener.clear(editText.getText());
}