안드로이드에서 비활성 InputConnection 경고의 getExtractedText
내 logcat에 다음 경고가 표시됩니다.
getExtractedText on inactive InputConnection
그 이유를 찾을 수 없습니다. 도와주세요
비슷한 문제가 발생했습니다. 내 로그 캣 :
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();
}
텍스트 (autotext, autocap, multitap, undo)뿐만 아니라 모든 입력 상태를 지우려면 TextKeyListener.clear (Editable e)를 사용할 수 있습니다 .
if (editText.length() > 0) {
TextKeyListener.clear(editText.getText());
}
최신 정보:
내가 InputConnection 경고를받는 이유는 텍스트를 설정 한 위치 (예 : onTextChanged콜백 또는 afterTextChanged) 때문이 아니기 때문 setText입니다.
전화로 문제를 해결했습니다.
hiddenKeyboardText.getText().clear();
hiddenKeyboardText.append("some string");
참고 : afterTextChanged콜백 에서 여전히 전화를 걸지만 경고없이 작동 ontextChanged합니다.
이전 답변 :
시나리오가 약간 다르지만 logcat에서도 동일한 메시지가 나타납니다. EditText에 들어온 모든 문자 (또는 작성된 문자 / 붙여 넣은 텍스트)를 읽은 다음 해당 EditText를 기본 초기화 문자열로 재설정하려고했습니다.
일반 텍스트 부분은 위의 Johnson의 솔루션에 따라 작동합니다. 그러나 텍스트를 재설정하는 데 문제가 있었고 입력 연결 경고가 표시됩니다.
처음에는 onTextChanged(CharSequence s, ...)다음과 같이 정의되었습니다.
@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;
}
When onTextChanged(...) is called, the EditText is in readonly mode. I am not sure if this means we can't do more than call getText.clear() on it (setText(...) calls produce inputConnection warnings as well).
However, the callback afterTextChanged(Editable s) is the right place to set the text.
@Override
public void afterTextChanged(Editable s) {
if (isResettingKeyboard)
return;
resetKeyboardString();
// ...
}
This is, thus far, working without any warnings.
From the help documents
http://developer.android.com/reference/android/view/inputmethod/InputConnection.html
The InputConnection interface is the communication channel from an InputMethod back to the application that is receiving its input. It is used to perform such things as reading text around the cursor, committing text to the text box, and sending raw key events to the application.
In addition, further reading shows
getExtractedText(): This method may fail either if the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple seconds to return). In either case, a null is returned.
It appears to also monitor changes to such text, and alert changes.
To hunt the issue down you'll have to explore any database queries you are making, perhaps around listViews or lists in a layout.
If you don't have any views, for example it's happening randomly in the background, then i would suggest that its not a UI element issue, so ignore textfields and such. It could be a background service that's storing information in a cursor or requesting a cursor.
Also, does the issue arise from your app? or perhaps someone else's that you've installed recently. List the full logCat trace. Someone might recognise the issue.
I would hazard a guess that if you haven't written something specific around this that its someone elses log message, or perhaps that of a library your using?
I was having the same problem. The warning appeared when the soft keyboard was activated in one of my EditTexts and the activity lose focus.
What I did was to hide the keyboard in onPause();
@Override
protected void onPause() {
// hide the keyboard in order to avoid getTextBeforeCursor on inactive InputConnection
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
super.onPause();
}
Solved this issue for myself maybe you have the same problem.
This was caused by an Object in the HeaderView of the List Adapter.
I inflated a View and declared the Object and put a TextWatcher on it.
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
}
});
Added it to the List Adapter and built the adapter.
JobListView = (ListView) getListView().findViewWithTag("JOBLISTVIEWTAG");
JobListView.addHeaderView(v, null, false);
JobsAdapter = new IN_JOBS_ADAPTER(CONTEXT, ITEMS_FOR_ADATER);
ListView.setAdapter(JOBSadapter);
Everything is fine the Text Watcher works.
BUT if I ever rebuilt the adapter after the initial build.
JobsAdapter = new IN_JOBS_ADAPTER(CONTEXT, DIFFERENT_ITEMS_FOR_ADAPTER);
ListView.setAdapter(JOBSadapter);
That HeaderView is rebuilt too.
That warning would show because the Object was removed and the Text Watcher was still set watching for it.
The List Adapter and Object were replaced, and I'm guessing the Text Watcher was looking the other way when it happened.
So the warning goes off and miraculously the Text Watcher finds the HeaderView and the Object. But it loses focus and logs that warning.
Using
JOBSadapter.notifyDataSetChanged();
fixed the issue.
BUT if you have an Object inside the Adapter, and the Text Watcher is attached to the Object inside the Adapter. Then you may need to do a little more work.
Try removing the Listener and attach it again after doing whatever work you may be doing.
Object.removeTextChangedListener();
or
Object.addTextChangedListener(null);
Aside from antoniom's answer, make sure that any further actions needed to be done, are really done after hiding the keyboard, so if you have hidden the keyboard like the one below:
public void hideKeyboard() {
InputMethodManager inputMethodManager =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}
, you need to have succeeding actions performed post the keyboard hiding, like so:
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
finish(); //Sample succeeding code
}
});
I had this problem when I had to modify or get text from EditText and it was focused.
So before modify or get from it, I closed keyboard and I fix it.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
Maybe, your problem is different.
I had solved my problem inserting a input type on xml like this: android:inputType="none|text|textCapWords|textUri"
before that was android:inputType="text" This solved my problem.
Error in Logcat: getTextBeforeCursor on inactive InputConnection
Solution: Hide Your Input Keyboard and run the application.
Hide software keyboard before clearing EditText - warnings will not be shown.
Also, It seems to be device specific. I've seen it only on Nexus 4 (Android 7.1). No warnings on emulators (8.0, 7.1) or Nexus 5.
'Programing' 카테고리의 다른 글
| Android 마켓 / 플레이 스토어에서 프로모션 및 기능 그래픽이란 무엇입니까? (0) | 2020.07.16 |
|---|---|
| JavaLaunchHelper 클래스는 둘 다에서 구현됩니다. (0) | 2020.07.16 |
| 이상적인 루비 프로젝트 구조 (0) | 2020.07.16 |
| 파이썬을 업데이트하는 방법? (0) | 2020.07.16 |
| jar 파일 내부에서 "폴더"리소스를 얻으려면 어떻게해야합니까? (0) | 2020.07.16 |