Do not close the cursor in the onCreate method. It refers to your adapter, but it is not used yet!
Try using LoaderManager / CursorLoader. This is a new way to handle cursors: How do I switch from managedQuery to LoaderManager / CursorLoader?
Here is an example from one of my projects (I have not tested this code):
public class AdditionalActivitiesListFragment extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener, OnClickListener { private SimpleCursorAdapter adapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] columns = new String[] { "your", "db", "columns" }; int[] to = new int[] { R.id.your, R.id.fields, R.id.toMapWith }; getLoaderManager().initLoader(0x02, null, this); adapter = new SimpleCursorAdapter(activity.getApplicationContext(), R.layout.row_layout, null, columns, to, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(adapter); } public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new SimpleCursorLoader(this) { @Override public Cursor loadInBackground() { Cursor c =
Source SimpleCursorLoader: https://gist.github.com/1217628 (via fooobar.com/questions/54587 / ... )
source share