Hi all,

The structure of some of my activities is a simple ListView with a
custom CursorAdapter.
The cursor is created in onCreate() on the activity from a SQLite
database.
The problem is that querying the SQLite database can be quite slow at
times with lots of data (and let's assume I've already optimized the
sql query as much as possible).  Because it occurs in onCreate() on
the UI thread, I get ugly black screens when opening the activity,
which sometimes turn into ANRs, on a slow phone like the G1.

I want to load the cursor in a background and show "Loading.." on
screen while doing so.
I saw AsyncQueryHandler used extensively in the framework, but this
seems a solution geared more towards Content Providers and not
application-local SQLite databases.
I then thought of trying to load the cursor in a background thread,
but realize that this might be problematic, as the CursorAdapter
should be instantiated in onCreate() and should take a cursor as a
parameter.

The latest thought I had was to instantiate an empty MatrixCursor in
onCreate() and pass that to the cursor adapter, while kicking off a
thread/TimerTask to query the database.  Then, on database cursor
load, call cursorAdapter.changeCursor to the properly filled cursor.
This doesn't seem very elegant and seems quite wasteful, however.

Does anyone have an approach that makes more sense?  Or am I stuck
with the MatrixCursor solution?

Thanks in advance.

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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to