Java android上的getExtractedText on inactive InputConnection警告
我在日志中得到以下警告Java android上的getExtractedText on inactive InputConnection警告,java,android,logcat,Java,Android,Logcat,我在日志中得到以下警告 getExtractedText on inactive InputConnection 我找不到背后的原因。请从帮助文档中获取帮助 InputConnection接口是来自 InputMethod返回到接收其输入的应用程序。它是 用于执行诸如读取光标周围的文本之类的操作, 将文本提交到文本框,并将原始密钥事件发送到 应用程序 此外,进一步阅读显示 getExtractedText(): 如果输入连接无效,此方法可能会失败 (例如进程崩溃)或客户端花费的时间太长 用文
getExtractedText on inactive InputConnection
我找不到背后的原因。请从帮助文档中获取帮助 InputConnection接口是来自 InputMethod返回到接收其输入的应用程序。它是 用于执行诸如读取光标周围的文本之类的操作, 将文本提交到文本框,并将原始密钥事件发送到 应用程序 此外,进一步阅读显示 getExtractedText(): 如果输入连接无效,此方法可能会失败 (例如进程崩溃)或客户端花费的时间太长 用文本回复(返回时间为几秒钟)。在里面 无论哪种情况,都会返回null 它似乎还监视这些文本的更改,并提醒更改 要找出问题所在,您必须探索正在进行的任何数据库查询,可能是围绕布局中的ListView或列表 如果您没有任何视图,例如,它是在后台随机发生的,那么我建议这不是一个UI元素问题,所以忽略文本字段等等。它可能是一个后台服务,将信息存储在游标中或请求游标 此外,这个问题是否由您的应用程序引起?或者你最近安装的其他人的。列出完整的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视图。当用户按下按钮时,编辑文本被清除。当我快速按下按钮时,大量非活动的InputConnection条目流出来
例:
上面日志中的最后一行很好地说明了正在发生的事情。果然,InputConnection被清除文本的请求淹没了。在尝试清除之前,我尝试修改代码以检查文本长度:
if (editText.length() > 0) {
editText.setText(null);
}
这有助于缓解快速按下按钮不再导致IIInputConnectionWrapper警告流的问题。然而,当用户在键入内容和按下按钮之间快速切换,或者当应用程序负载足够大时按下按钮,等等时,这仍然容易出现问题
幸运的是,我找到了另一种清除文本的方法:。这样我就不会收到任何警告:
if (editText.length() > 0) {
editText.getText().clear();
}
请注意,如果您希望清除所有输入状态,而不仅仅是文本(自动图文集、自动映射、多重映射、撤消),则可以使用
我也有同样的问题。当在my
EditText
的其中一个文本中激活软键盘时,该警告出现,并且该活动失去焦点
我所做的是将键盘隐藏在onPause()中
我自己解决了这个问题也许你也有同样的问题 这是由列表适配器的头视图中的对象造成的 我膨胀了一个视图,声明了对象,并在其上放置了一个文本观察者
View v = LayoutInflater.from(CONTEXT).inflate(R.layout.in_overscrollview, null);
Object= (Object) v.findViewById(R.id.OBJECT_ID);
Object.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//Do my work
//Update my view
}
});
将其添加到列表适配器中并构建适配器
JobListView = (ListView) getListView().findViewWithTag("JOBLISTVIEWTAG");
JobListView.addHeaderView(v, null, false);
JobsAdapter = new IN_JOBS_ADAPTER(CONTEXT, ITEMS_FOR_ADATER);
ListView.setAdapter(JOBSadapter);
一切都很好,文本观察程序工作正常
但是如果在初始构建之后重新构建适配器
JobsAdapter = new IN_JOBS_ADAPTER(CONTEXT, DIFFERENT_ITEMS_FOR_ADAPTER);
ListView.setAdapter(JOBSadapter);
该头视图也被重建
显示该警告是因为对象已被删除,而文本监视程序仍在监视该对象
列表适配器和对象被替换,我猜文本观察器在发生这种情况时正朝着另一个方向看
因此,警告消失了,文本观察程序奇迹般地找到了标题视图和对象。但它失去了焦点并记录了警告
使用
JOBSadapter.notifyDataSetChanged();
修正了这个问题
但是如果在适配器内有一个对象,并且文本观察程序附加到适配器内的对象。那么你可能需要做更多的工作
尝试删除侦听器,并在完成任何工作后重新连接它
Object.removeTextChangedListener();
或
除了antoniom的回答之外,请确保所有需要执行的进一步操作都是在隐藏键盘后执行的,因此如果您像下面这样隐藏了键盘:
public void hideKeyboard() {
InputMethodManager inputMethodManager =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}
,您需要在键盘隐藏后执行后续操作,如下所示:
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
finish(); //Sample succeeding code
}
});
更新: 我收到InputConnection警告的原因不是因为我设置文本的位置(即,在
onTextChanged
回调中,或posterextchanged
),而是因为我使用的是setText
我通过打电话来回避这个问题:
hiddenKeyboardText.getText().clear();
hiddenKeyboardText.append("some string");
注意:我仍然在posterextchanged
回调中进行调用,尽管它在ontextChanged
中也没有警告
先前的答案:
我在logcat中也得到了相同的消息,尽管我的场景略有不同。我想读取进入EditText(或合成字符/粘贴文本)的每个字符,然后将有问题的EditText重置为默认初始化字符串
明文部分按照上述Johnson的解决方案工作。然而,重置文本是有问题的,我会收到inputconnection警告
最初,我的onTextChanged(CharSequence,…)
定义如下:
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (isResettingKeyboard)
return;
// ... do what needs to be done
resetKeyboardString();
}
public void resetKeyboardString()
{
isResettingKeyboard = true;
hiddenKeyboardText.getText().clear();
hiddenKeyboardText.setText(keyboardInitString);
hiddenKeyboardText.setSelection(defaultKeyboardCursorLocation);
isResettingKeyboard = false;
}
调用onTextChanged(…)
时,EditText处于只读模式。我不确定这是否意味着我们只能对它调用getText.clear()
(setText(…)
调用prod
public void hideKeyboard() {
InputMethodManager inputMethodManager =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
finish(); //Sample succeeding code
}
});
hiddenKeyboardText.getText().clear();
hiddenKeyboardText.append("some string");
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (isResettingKeyboard)
return;
// ... do what needs to be done
resetKeyboardString();
}
public void resetKeyboardString()
{
isResettingKeyboard = true;
hiddenKeyboardText.getText().clear();
hiddenKeyboardText.setText(keyboardInitString);
hiddenKeyboardText.setSelection(defaultKeyboardCursorLocation);
isResettingKeyboard = false;
}
@Override
public void afterTextChanged(Editable s) {
if (isResettingKeyboard)
return;
resetKeyboardString();
// ...
}
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
`Widget build(BuildContext context) {
final _formKey = GlobalKey<FormState>();
final prodName = TextEditingController();
final prodDesc = TextEditingController();
final prodPrice = TextEditingController();
...`
`final _formKey = GlobalKey<FormState>();
final prodName = TextEditingController();
final prodDesc = TextEditingController();
final prodPrice = TextEditingController();
...
Widget build(BuildContext context) {`