Reputation: 11861
I'm doing simply queries like:
Cursor c = databaseHelper.getReadableDatabase().rawQuery("select " + MyTable.TABLE_FIELD.getColumnName() + " from " + MyTable.TABLE_NAME, null);
after that I extract the data needed and populate some views.
c.close();
Everything works as expected. I have a share intent to send an e-mail with some of the information shown. The java.lang.IllegalStateException
is thrown after the e-mail app sends the e-mail or closes and my activity is brought back to "life".
This exception is only thrown in this situation, if I send it to background and then call it again this exception isn't thrown. I even have an intent to open youtube and play a video and this exception isn't thrown...
I really don't know why this is happening.
Thanks for your time.
ps: I've tried //c.close();
but it didn't work either.
Upvotes: 2
Views: 2365
Reputation: 11
This worked for me..
public void onBackPressed() {
Intent i = new Intent(getApplicationContext(), ClassName.class);
startActivity(i);
finish();
super.onStop();
}
Upvotes: 0
Reputation: 11861
I found what was causing this problem. Some of the e-mail's information was fed by another cursor from an "utils" class. This cursor was closed after providing the information to the e-mail and this was causing the problem. Instead of c.close();
I changed to c = null;
and now it's working.
Probably not the best solution, but for now it's working. Thanks.
Upvotes: 1
Reputation: 7881
You could use c.requery()
but it was deprecated in API level 11.
Don't use this. Just request a new cursor, so you can do this asynchronously and update your list view once the new cursor comes back.
Performs the query that created the cursor again, refreshing its contents. This may be done at any time, including after a call to deactivate(). Since this method could execute a query on the database and potentially take a while, it could cause ANR if it is called on Main (UI) thread. A warning is printed if this method is being executed on Main thread.
Upvotes: 2