Java.lang.illegalstateexception: Attempt To Re-open An Already-closed Object
I'm trying to figure out why occasionally I'm getting the IllegalStateException. I can't find any good examples that show how to load a list using a thread to query a SQLite datab
Solution 1:
Look into AsyncQueryHandler if you want to query DB the way you want.
Your task RetrieveCursorTask is running on separate thread so when your activity gets destroyed your AsyncTask might still be running in background but as you have closed your cursor in main activity onDestroy it might be requeried again after your AsyncTask returns.
Solution 2:
Sounds like you need to syncronize the block where you set your adapter in onPostExecute. The problem is since AsyncTask is running on a separate thread, the order in which the cursor is set and subsequently requested isn't guaranteed. Try this..
@OverrideprotectedvoidonPostExecute(Cursor cursor) {
super.onPostExecute(cursor);
synchronized(anyObject) {
if (cursor != null) {
try {
adapter = newMyCursorAdapter(ctx, cursor);
} catch (Exception e) {
}
setListAdapter(adapter);
}
}
}
Post a Comment for "Java.lang.illegalstateexception: Attempt To Re-open An Already-closed Object"