InputConnectionWrapper警告

时间:2012-09-07 12:52:19

标签: android warnings

每当我的应用程序可见时,我每次关闭屏幕时都会收到一个InputConnectionWrapper警告。我不知道为什么,因为我不使用InputConnection

这是LogCat输出。

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

5 个答案:

答案 0 :(得分:0)

猜测已经来不及帮助,但在我的情况下,问题是我有一个" setOnEditorActionListener "在文本编辑上 - 如果我删除了这个监听器,警告就会消失。

答案 1 :(得分:0)

在我的情况下,在按钮布局中我有这个:android:textIsSelectable="true",只是删除它并解决了问题......

答案 2 :(得分: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);
            }          
        }
    }
};

答案 3 :(得分:0)

我正在使用webView浏览需要注册或登录的URL。当我将焦点切换到另一个TextField时,我的应用程序冻结了,并且上面出现了相同的错误。

我设法解决此问题的原因是,它缺少下面的这段关键代码:

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

此代码应位于扩展主类的实例类的声明之后以及构建Widget函数之前。

在错误日志中,您仍然可能会看到相同的警告,但是它肯定会解决引起的任何问题,无论是Swift键盘还是TextField本身。

答案 4 :(得分:-4)

事实证明,InputConnectionWrapper的上述用法完全正确。但是,commitText()永远不会被调用(特殊情况除外),因为还有其他方法在打字时使用。这些主要是setComposingText()sendKeyEvent()

但是,重要的是覆盖很少使用的方法,如deleteSurroundingText()commitText(),以确保捕获每个用户输入,因为我遇到了类似的问题。

我的情况:我有一个EditText用户输入的视图。当用户按下按钮时,EditText被清除。当我快速按下按钮时,大量不活动的InputConnection条目流出。

E.g。 editText.setText(null);

上面我的logcat中的最后一行提供了一个很好的指示。果然,InputConnection对清除文本的请求感到不知所措。我尝试修改代码以检查文本长度,然后再尝试清除它:

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

这有助于缓解快速按下按钮不再导致IInputConnectionWrapper警告流的问题。然而,当用户在应用程序负载充足等情况下快速切换内容并按下按钮或按下按钮等时,仍然会出现问题。

幸运的是,我找到了另一种清除文字的方法:Editable.clear()。有了这个,我根本没有得到警告:

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

请注意,如果您希望清除所有输入状态而不仅仅是文本(自动文本,自动播放,多键,撤消),您可以使用TextKeyListener.clear(Editable e)

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

如果您想了解有关输入连接包装的更多信息,请访问以下链接。

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