Hi Mark, As i said , i am doing the operation in a "background thread". I also know that cursor.moveToFirst() causes the data to be accessed at that point. Here is the code
public void getAllSongIdsOffset(int offset, int limit) { int nTrackId; try { SQLiteDatabase db = InventoryManager.inventoryDB.getConnection(); Cursor mCursor; int index = 0; mCursor = db.rawQuery( "select distinct id from tracks order by tracks.namelimit " + limit + " offset " + offset + "", null); SQLiteDatabase.releaseMemory(); if (mCursor != null) { Log.i("VALUE----->", "Before movetoFirst" + System.currentTimeMillis()); mCursor.moveToFirst(); Log.i("VALUE----->", "After movetoFirst" + System.currentTimeMillis()); if (mCursor.getCount() == 0) { mCursor.close(); SQLiteDatabase.releaseMemory(); System.gc(); return; } do { // songIds[index] = new Integer(mCursor.getInt(0)); mediaIdArray.set(offset + index, mCursor .getInt(0)); index++; } while (mCursor.moveToNext()); } mCursor.close(); mCursor = null; } catch (Exception e) { e.printStackTrace(); } finally { InventoryManager.inventoryDB.releaseConnection(); } SQLiteDatabase.releaseMemory(); } private class ListThread extends Thread { public void run() { int size = mediaIdArray.size(); while (offset <= InventoryManager.songs.getAllSongCount()) { try { Thread.sleep(10000); int cnt = offset + limit; if (cnt > size) cnt = size; InventoryManager.songs.getAllSongIdsOffset(offset, limit); offset += 1000; ListScreenHandler .sendEmptyMessage(ScreenConstants.NOTIFYDATASETCHANGED); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } If i dont do a Thread.sleep... the UI gets completely blocked until all the records are fetched.\ To update the UI i am calling a handler. Thanks , Alok. On Tue, Jul 20, 2010 at 5:10 PM, anil kukreti <success.anil...@gmail.com>wrote: > > Ya Mark is right ! > > You need to use *multithreading* for making a reponsive UI. > > Thread.sleep inside spawned thread will give a chance to main UI thread to > response to User events. > > > ---------- Forwarded message ---------- > From: Alok Kulkarni <kulsu...@gmail.com> > Date: Tue, Jul 20, 2010 at 4:44 PM > Subject: [android-developers] cursor.moveToFirst() blocking UI > To: android-developers@googlegroups.com > > > Hi, > I have a background thread which queries for 1000 records at a time. After > querying , when i call cursor.moveToFirst(), the UI gets blocked until the > operation is completed.This is very disturbing experience for user , > especially if there are 10000 plus records.I use Thread.sleep in between > after each 1000 records, As soon as cursor.moveToFirst is called, UI blocks > for 2 3 seconds. > Am i missing anything here ? > > -- > 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<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > > > > -- > Thanks for Cooperating! > Anil Kukreti > > Network transforms ideas to reality. > 09312646623 > Linked In : http://in.linkedin.com/in/anilkukreti > Blog : http://androidosbeginning.blogspot.com/ > Skype Id : anil.kleward > > -- > 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<android-developers%2bunsubscr...@googlegroups.com> > 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 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