Android: SQLiteCursor / SimpleCursorAdapter in the background

My problem is with Android. I have the following code (non-skipping parts omitted):

public class MyActivity extends ListActivity {
    protected void onResume() {
        super.onResume();
        new UpdateTask().execute();
    }

    private class UpdateTask extends AsyncTask<Object, Object, ListAdapter> {
        protected ListAdapter doInBackground(Object... params) {
            SQLiteCursor cursor = db.getSomeData();
            startManagingCursor(cursor);
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, ..., cursor, ..., ...);
            return adapter;
        }

        protected void onPostExecute(ListAdapter result) {
            listView.setAdapter(result);
        }
    }
 }

This throws a RuntimeException - "Cannot create a handler inside a thread that did not call Looper.prepare ()" on the line where the SimpleCursorAdapter is instantiated.

I understand why this is happening, I just don’t know how to fix it (keeping this in a separate thread). I found this thread:

http://groups.google.com/group/android-developers/browse_thread/thread/34d0069bb2de925e?fwc=2

But I do not quite understand the answer. I have failed the Google example with SQLiteCursor and AsyncQueryHandler.

Could you guys help? Thank.

+3
source share
2 answers

, SimpleCursorAdapter . , doInBackground() return cursor onPostExecute().

. Threading, .

+5

Looper.prepare(); , ​​

0

Source: https://habr.com/ru/post/1795840/


All Articles