Android is complaining that the code below needs to call Looper.prepare. I have tried adding Looper.prepare but the code crashes after the sixth execution, leading me to believe that it wasn't as simple as I th开发者_运维技巧ought. Any suggestion would be appreciated. Incidentally I wrapped this code in AsyncTask cause I needed a progress spinner while the query was being executed. If there is something simpler, please let me know.
private class doSearch extends AsyncTask<String, String, Cursor> {
@Override
protected Cursor doInBackground(String... searchstring) {
[...]
CursorLoader loader = new CursorLoader(SearchActivity.this, codes, projection, mWhere, null, null);
Cursor cursor = loader.loadInBackground();
return cursor;
}
It usually means you are doing something UI related or calling a handler's sendMessage function from another (background) Thread than the main thread
You are Already in an AsyncTask. Async Task Loader is going to create another AsyncTask that is rooted within your threadpool. AsyncTasks have to be constructed on the UI thread. They will use this to grab the Looper needed. If you are going to write an async task yourself and want to bite off this cursor load in serial then use a non async cursor retrieving way. Or get rid of your AsyncTask and extend CursorLoader and override the deliverResult(Cursor) method to act as your callback. This would be similar to onPostExecute within AsyncTask
精彩评论