Hello team,

I have ListView with the attached CursorAdapter.
For known reasons I want to call cursor.requery() on non-UI thread
(using AsyncTask) but it fails with the
CalledFromWrongThreadException.
As I understand the adapter tries to update UI from the thread where
requery() method was called.

Is it possible somehow to make adapter update UI from UI-thread on
calling requery in non-UI thread.

The exception:
Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only
the original thread that created a view hierarchy can touch its views.
        at android.view.ViewRoot.checkThread(ViewRoot.java:2692)
        at android.view.ViewRoot.clearChildFocus(ViewRoot.java:1518)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.ViewGroup.clearChildFocus(ViewGroup.java:507)
        at android.view.View.clearFocus(View.java:2569)
        at android.view.ViewGroup.clearFocus(ViewGroup.java:516)
        at android.view.View.setFlags(View.java:4343)
        at android.view.View.setFocusable(View.java:3093)
        at android.widget.AdapterView.checkFocus(AdapterView.java:695)
        at android.widget.AdapterView
$AdapterDataSetObserver.onInvalidated(AdapterView.java:813)
        at
android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:
43)
        at
android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:
54)
        at android.widget.CursorAdapter
$MyDataSetObserver.onInvalidated(CursorAdapter.java:391)
        at
android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:
43)
        at
android.database.AbstractCursor.deactivateInternal(AbstractCursor.java:
89)
        at android.database.AbstractCursor.deactivate(AbstractCursor.java:78)
        at
android.database.BulkCursorToCursorAdaptor.deactivate(BulkCursorToCursorAdaptor.java:
111)
        at
android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:
154)
        at android.database.CursorWrapper.requery(CursorWrapper.java:211)
        at MyActivity$2.doInBackground(MyActivity.java:110)
        at android.os.AsyncTask$2.call(AsyncTask.java:185)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

Code used:
// requery in non-UI thread
new AsyncTask() {
        protected Object doInBackground(Object... params) {
                mCursor.requery(); // exception is thrown here
                return params;
        }
}

Thanks in advance,
Gennadi Kudrjavtsev


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to