Bug 1257667 - Try to catch stale cursor usage using LeakCanary r=sebastian

MozReview-Commit-ID: Ga5lPgwpIxp
This commit is contained in:
Andrzej Hunt 2016-03-17 13:55:00 -07:00
Родитель 1df58c3516
Коммит 4ca8060282
1 изменённых файлов: 6 добавлений и 0 удалений

Просмотреть файл

@ -23,6 +23,8 @@ import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
import org.mozilla.gecko.GeckoApplication;
/**
* A copy of the framework's {@link android.content.CursorLoader} that
* instead allows the caller to load the Cursor themselves via the abstract
@ -87,6 +89,10 @@ abstract class SimpleCursorLoader extends AsyncTaskLoader<Cursor> {
}
if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
// Trying to read from the closed cursor will cause crashes, hence we should make
// sure that no adapters/LoaderCallbacks are holding onto this cursor.
GeckoApplication.getRefWatcher(getContext()).watch(oldCursor);
oldCursor.close();
}
}