views:

35

answers:

1

In my Android application user can fill database with imported data, then perform predefined, complex SQL query. With some data pattern, query will take very long (minutes and more on HTC Hero), while common usage will not exceed 10-15 seconds.

Is there any way to cancel pending SQLite query on Android? Timeout would be as good as well, partial results are not required. I'm performing query within AsyncTask.doInBackground()

I know best way is optimize query or change app logic, but in this case results depends on user knowledge anyway, so I'd like to help those who enter troublesome pattern.

A: 

ASyncTask supports cancellation and the flag should cancel all, including your SQL Query.

ASyncTask.cancel(boolean mayInterruptIfRunning)
WarrenFaith
This is not enough. Code from `doInBackground()` is in fact left alone as AsyncTask flow returns via `onCancelled()`, but Cursor still hangs on `moveToFirst()` and sucks whole CPU. I tried to close SQLiteDatabase or SQLiteOpenHelper but any call to this objects blocks execution until `moveToFirst()` is done. And Cursor has no "cancel" method.
tomash
ok, thanks for this, thought it would be otherwise.
WarrenFaith