am 186aa619: Cleanup probable causes of close cursor access

Merge commit '186aa619dca002790c38b4dd8649bfe2b3a96f6e' into froyo-plus-aosp

* commit '186aa619dca002790c38b4dd8649bfe2b3a96f6e':
  Cleanup probable causes of close cursor access
This commit is contained in:
Andrew Stadler 2010-04-15 00:18:40 -07:00 committed by Android Git Automerger
commit 1bf66bb8fc

View File

@ -62,6 +62,7 @@ import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
@ -169,8 +170,6 @@ public class AccountFolderList extends ListActivity implements OnItemClickListen
} }
((TextView) findViewById(R.id.title_left_text)).setText(R.string.app_name); ((TextView) findViewById(R.id.title_left_text)).setText(R.string.app_name);
mLoadAccountsTask = (LoadAccountsTask) new LoadAccountsTask().execute();
} }
@Override @Override
@ -346,7 +345,7 @@ public class AccountFolderList extends ListActivity implements OnItemClickListen
Cursor c1 = getSummaryChildCursor(); Cursor c1 = getSummaryChildCursor();
// TODO use a custom projection and don't have to sample all of these columns // TODO use a custom projection and don't have to sample all of these columns
Cursor c2 = AccountFolderList.this.managedQuery( Cursor c2 = getContentResolver().query(
EmailContent.Account.CONTENT_URI, EmailContent.Account.CONTENT_URI,
EmailContent.Account.CONTENT_PROJECTION, null, null, null); EmailContent.Account.CONTENT_PROJECTION, null, null, null);
Long defaultAccount = Account.getDefaultAccountId(AccountFolderList.this); Long defaultAccount = Account.getDefaultAccountId(AccountFolderList.this);
@ -355,9 +354,16 @@ public class AccountFolderList extends ListActivity implements OnItemClickListen
@Override @Override
protected void onPostExecute(Object[] params) { protected void onPostExecute(Object[] params) {
if (params == null || ((Cursor)params[1]).isClosed()) { if (isCancelled() || params == null || ((Cursor)params[1]).isClosed()) {
return; return;
} }
// Before writing a new list adapter into the listview, we need to
// shut down the old one (if any).
ListAdapter oldAdapter = mListView.getAdapter();
if (oldAdapter != null && oldAdapter instanceof CursorAdapter) {
((CursorAdapter)oldAdapter).changeCursor(null);
}
// Now create a new list adapter and install it
mListAdapter = AccountsAdapter.getInstance((Cursor)params[0], (Cursor)params[1], mListAdapter = AccountsAdapter.getInstance((Cursor)params[0], (Cursor)params[1],
AccountFolderList.this, (Long)params[2]); AccountFolderList.this, (Long)params[2]);
mListView.setAdapter(mListAdapter); mListView.setAdapter(mListAdapter);