Bug 856739 - AwesomeBar.onDestroy does DB access on the main thread r=lucasr

This commit is contained in:
Mark Finkle 2013-04-08 15:41:50 -04:00
Родитель 6aab04ff84
Коммит b59e551f4a
2 изменённых файлов: 29 добавлений и 15 удалений

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

@ -147,19 +147,26 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
@Override
public void destroy() {
AwesomeBarCursorAdapter adapter = getCursorAdapter();
unregisterEventListener("SearchEngines:Data");
if (adapter == null) {
return;
}
Cursor cursor = adapter.getCursor();
if (cursor != null)
cursor.close();
mHandler.removeMessages(MESSAGE_UPDATE_FAVICONS);
mHandler.removeMessages(MESSAGE_LOAD_FAVICONS);
mHandler = null;
// Can't use getters for adapter or listview. They will create them if null.
if (mCursorAdapter != null && mListView != null) {
mListView.setAdapter(null);
final Cursor cursor = mCursorAdapter.getCursor();
// Gingerbread locks the DB when closing a cursor, so do it in the
// background.
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (cursor != null && !cursor.isClosed())
cursor.close();
}
});
}
}
public void filter(String searchTerm) {

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

@ -93,14 +93,21 @@ public class BookmarksTab extends AwesomeBarTab {
@Override
public void destroy() {
BookmarksListAdapter adapter = getCursorAdapter();
if (adapter == null) {
return;
// Can't use getters for adapter. It will create one if null.
if (mCursorAdapter != null && mView != null) {
ListView list = (ListView)mView;
list.setAdapter(null);
final Cursor cursor = mCursorAdapter.getCursor();
// Gingerbread locks the DB when closing a cursor, so do it in the
// background.
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (cursor != null && !cursor.isClosed())
cursor.close();
}
});
}
Cursor cursor = adapter.getCursor();
if (cursor != null)
cursor.close();
}
@Override