Hi Mark,
Thanks for your reply. What i did was i removed the System.gc() as well as
the handler call.
Considering the code  from above snippet.

     Log.i("VALUE----->", "Before movetoFirst" +
System.currentTimeMillis());
     mCursor.moveToFirst();
     Log.i("VALUE----->", "After movetoFirst" + System.currentTimeMillis());

Output :-
               Before movetoFirst 1279628503040
               After movetoFirst    1279628508063
This clearly shows a difference of 5 seconds.(My emulator is slow.On device
it takes 2 to 3 seconds)
Thanks,
Alok.

On Tue, Jul 20, 2010 at 5:40 PM, Mark Murphy <[email protected]>wrote:

> With respect to your " If i dont do a Thread.sleep... the UI gets
> completely blocked until all the records are fetched.", the problem
> would appear to be in whatever your Handler is doing, or possibly just
> due to all the garbage collection you are doing. None of the code you
> show here, other than the GC, should block the UI thread, from what I
> can tell.
>
> Bear in mind that the code you have here is only copying a bunch of ID
> values. Assuming your UI is displaying things other than ID numbers,
> there must be other database I/O going on -- perhaps it is that I/O
> that is causing your problem.
>
> On Tue, Jul 20, 2010 at 7:56 AM, Alok Kulkarni <[email protected]> wrote:
> > 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.name
> > limit "
> >                             + 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 <[email protected]
> >
> > 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 <[email protected]>
> >> Date: Tue, Jul 20, 2010 at 4:44 PM
> >> Subject: [android-developers] cursor.moveToFirst() blocking UI
> >> To: [email protected]
> >>
> >>
> >> 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
> [email protected]
> >> To unsubscribe from this group, send email to
> >> [email protected]<android-developers%[email protected]>
> >> 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
> [email protected]
> >> To unsubscribe from this group, send email to
> >> [email protected]<android-developers%[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]<android-developers%[email protected]>
> > For more options, visit this group at
> > http://groups.google.com/group/android-developers?hl=en
>
>
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> _The Busy Coder's Guide to Android Development_ Version 3.1 Available!
>
> --
> 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]<android-developers%[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

Reply via email to