Yes, there is another thread, doing DB access as well. But I'm wondering about the general case: in general, doing any DB access (even queries/reads) can cause ANRs (the filesystem can be blocked, another thread or even another process could access the same DB, etc). So the question is: is CursorAdapter safe or not? Or what is the proper way of using it?
/Pal On Apr 4, 10:08 am, Kostya Vasilyev <[email protected]> wrote: > Reading should be Ok, perhaph there is something unusual going on in your > code? > > The last function on the stack is SqliteDatabase.lock - do you perhaps have > a background thread that also locks the database for a long time? > > -- Kostya > > 2011/4/4 space <[email protected]> > > > > > > > > > Hi! > > > I got an ANR in an application which used the CursorAdapter, and I > > started thinking if it's allowed to be used or not. > > It's pretty common to create a ListActivity (or just an Activity with > > a ListView) and set a CursorAdapter as adapter to it. However when the > > data set changes, the CursorAdapter gets the callback and calls > > requery (of it's enabled of course). However this requery could result > > in a database access, which is really bad in the main thread (like in > > my case). > > > This is the stacktrace: > > > android.database.sqlite.SQLiteDatabase.lock (SQLiteDatabase.java:378) > > android.database.sqlite.SQLiteQuery.fillWindow (SQLiteQuery.java:64) > > android.database.sqlite.SQLiteCursor.fillWindow (SQLiteCursor.java: > > 287) > > android.database.sqlite.SQLiteCursor.getCount (SQLiteCursor.java:268) > > android.database.CursorWrapper.getCount (CursorWrapper.java:70) > > android.database.MergeCursor.getCount (MergeCursor.java:61) > > android.widget.CursorAdapter.getCount (CursorAdapter.java:132) > > android.widget.HeaderViewListAdapter.getCount > > (HeaderViewListAdapter.java:132) > > android.widget.AdapterView$AdapterDataSetObserver.onChanged > > (AdapterView.java:782) > > android.database.DataSetObservable.notifyChanged > > (DataSetObservable.java:31) > > android.widget.BaseAdapter.notifyDataSetChanged (BaseAdapter.java:50) > > android.widget.CursorAdapter$MyDataSetObserver.onChanged > > (CursorAdapter.java:385) > > android.database.DataSetObservable.notifyChanged > > (DataSetObservable.java:31) > > android.database.AbstractCursor.requery (AbstractCursor.java:97) > > android.database.sqlite.SQLiteCursor.requery (SQLiteCursor.java:548) > > android.database.CursorWrapper.requery (CursorWrapper.java:211) > > android.database.MergeCursor.requery (MergeCursor.java:249) > > android.widget.CursorAdapter.onContentChanged (CursorAdapter.java:361) > > android.widget.CursorAdapter$ChangeObserver.onChange > > (CursorAdapter.java:377) > > android.database.ContentObserver$NotificationRunnable.run > > (ContentObserver.java:43) > > android.os.Handler.handleCallback (Handler.java:587) > > android.os.Handler.dispatchMessage (Handler.java:92) > > android.os.Looper.loop (Looper.java:123) > > android.app.ActivityThread.main (ActivityThread.java:3701) > > java.lang.reflect.Method.invokeNative > > java.lang.reflect.Method.invoke (Method.java:507) > > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > > (ZygoteInit.java:866) > > com.android.internal.os.ZygoteInit.main (ZygoteInit.java:624) > > dalvik.system.NativeStart.main > > > So, does this mean that simply using CursorAdapter (with > > autoRequery=true) is dangerous? If yes, what is the proper way to use > > it? > > > Thanks in advance! > > /Pal Szasz > > > -- > > 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 -- 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

