android上的非活动InputConnection警告上的getExtractedText [英] getExtractedText on inactive InputConnection warning on android

查看:48
本文介绍了android上的非活动InputConnection警告上的getExtractedText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 logcat 中收到以下警告.

I get the following warning in my logcat.

getExtractedText on inactive InputConnection

我无法找到其背后的原因.请帮忙

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

推荐答案

我遇到了类似的问题.我的日志:

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.

我的情况:我有一个用户输入的 EditText 视图.当用户按下按钮时,EditText 被清除.当我快速按下按钮时,会流出许多非活动的 InputConnection 条目.

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.

例如:

editText.setText(null);

上面我的 logcat 中的最后一行很好地说明了正在发生的事情.果然,InputConnection 被清除文本的请求淹没了.我尝试修改代码以检查文本长度,然后再尝试清除它:

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);
}

这有助于缓解快速按下按钮不再导致 IInputConnectionWrapper 警告流的问题.然而,当用户在输入内容和按下按钮之间快速交替或在应用程序负载充足时按下按钮等时,这仍然容易出现问题.

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();
}

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

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());
}

这篇关于android上的非活动InputConnection警告上的getExtractedText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆