Answer the question
In order to leave comments, you need to log in
How to remove a leaked TextWatcher?
I am using a TextWatcher to filter data in an ArrayAdapter. But when I exit the application, this listener remains in memory and keeps the entire application, despite the fact that I remove it from EditText'a in OnDestroy (), which was always called
TextWatcher watcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
arrayAdapter.getFilter().filter(s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {}
@Override
public void afterTextChanged(Editable s) {}
};
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
mActionTypeField.removeTextChangedListener(watcher);
watcher = null;
mActiveCursor.close();
super.onDestroy();
}
Answer the question
In order to leave comments, you need to log in
Install to onStart()
, uninstall to onStop()
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question