12

每当我的应用可见时关闭屏幕时,我都会收到 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
4

5 回答 5

0

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

我如何设法解决它是它缺少下面这段关键的代码:

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

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

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

于 2020-10-19T10:24:31.620 回答
0

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

于 2016-11-08T20:13:08.980 回答
0

猜想已经太晚了,但在我的情况下,我在文本编辑上有一个“ setOnEditorActionListener ”的问题——如果我删除了这个监听器,警告就消失了。

于 2016-02-29T15:35:49.917 回答
-1
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);
            }          
        }
    }
};
于 2019-07-11T08:46:37.347 回答
-7

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

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

我的情况:我有一个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();
}

请注意,如果您希望清除所有输入状态而不仅仅是文本(autotext、autocap、multitap、undo),您可以使用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

于 2014-03-27T12:35:08.360 回答