In case that sqlite database is quite big, preparation for using cursor requires lots of time-consuming-operation.
So, developer may considering about asynchronous way - showing progress while preparing cursor in background.
Then, what is 'Really' time-consuming-operation in preparing cursor?
As my understanding, in Android sqlite cursor, the answer is first 'fillWindow' operation of SQLiteCursor.
Notable thing is, at sqlite cursor, creating cursor doesn't do any real (or practical) thing.
So, creating cursor is done very quickly.
By the way, Sqlite cursor do 'fillWindow' operation at the moment of first 'getCount()' call - See SQLiteCursor.java.
Therefore, to prepare cursor in background, not only creating cursor but also calling first 'getCount()' function are required.
Here is sample function for reference.
public void reloadCursorAsync() { DiagAsyncTask.Worker worker = new DiagAsyncTask.Worker() { private Cursor newCursor; @Override public void onPostExecute(DiagAsyncTask task, Err result) { changeCursor(newCursor); } @Override public Err doBackgroundWork(DiagAsyncTask task, Object... objs) { newCursor = createCursor(); newCursor.getCount(); return Err.NO_ERR; } }; new DiagAsyncTask(mContext, worker, DiagAsyncTask.Style.SPIN, R.string.loading, false) .execute(); }
'Domain > Android' 카테고리의 다른 글
[Android] MediaPlayer with SurfaceHolder (0) | 2012.10.18 |
---|---|
[Android] SurfaceView + SlidingDrawer issue (0) | 2012.10.17 |
[Android] Issue regarding android:targetSdkVersion. (0) | 2012.10.08 |
Policy of Google Play to consider registering App to Android Google Play. (0) | 2012.10.04 |
Points to consider for recycling Bitmap of ImageView. (0) | 2012.09.21 |