> A crude use case example is where the records are like short log
> entries, and you want to scroll through them to watch events over a
> time span.  You need a big window, since in some time frames, there
> may be few records; in others, there may be thousands -- the data
> density varies & you can't just give them an index since they may not
> know what time range will cover what they need to know.

That still doesn't mean you should be loading 20K records in a single query.

> I'm doing the query & changing the SimpleCursorAdapter cursor in the
> background via AsyncTask, then binding the adapter to the list in
> onPostExecute.  Binding to the list has to be done in the UI thread,
> hence the UI freeze during the bind (as the list requests the row
> count from the adapter).

Correct. The "UI freeze" timing is because a query is done lazily -- the
query is not truly executed against the database until data is actually
needed. A call to getCount() is the likely first statement that will
trigger the actual query.

Hence, don't load 20K records in a single query.

> Now, I can avoid the UI freeze by doing a cursor.getCount (source of
> the delay) before binding to the list, but then I have some cursor
> management issues when the activity goes away due to a rotate --
> either stall the onStop/onDestroy until the cursor.getCount completes
> & the cursor can be closed, or keep the cursor static & risk the
> overhead if it is abandoned.

Or handle the UI change yourself by indicating in the manifest you will
handle those configuration changes, then override onConfigurationChanged()
and adjust your UI as needed.

> Unless I'm misunderstanding your suggestion, paging won't work because
> you'd still need to know the row count (incur delay) before deciding
> if/how to paginate.

Use the LIMIT and OFFSET terms on your SELECT statement to obtain data in
smaller chunks. Create a wrapping adapter (like my EndlessAdapter) that
only loads chunks when the user scrolls to the bottom of the list and
therefore needs more data.

http://github.com/commonsguy/cwac-endless

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


-- 
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

Reply via email to