S
S
samarjan2015-01-28 08:57:16
Android
samarjan, 2015-01-28 08:57:16

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
ca34631dc06a4004acdc600129c2184d.png

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

1 answer(s)
D
Denis Zagaevsky, 2015-01-29
@zagayevskiy Curated by Android Tag

Install to onStart(), uninstall to onStop().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question