0

Im building a contact application. In the main activity i have a listview, where i show the contacts.

I'm using a CursorAdapter to handle tha cursor with the list

It all works well without photos.

However, when i try to use photos the scrolling becomes laggish.

Thc calling to open the input stream is very slow, even if the inputStream is null and there's no image to load:

public static Bitmap loadContactPhoto(ContentResolver cr, long  id) 
{
   Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
   InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);

   if (input == null) 
   {
       return null;
   }

   return BitmapFactory.decodeStream(input);
}

What can I do about it?

dor506
  • 5,246
  • 9
  • 44
  • 79

1 Answers1

0

Are you loading the images in the UI thread.... If yes,you should not do it as this would block the thread and make the user experiance sluggish.

You should probably learn on lazy loading of images....try googling it out....

I would also not do database operations on the UI thread...eventhough some say it is ok to do small DB ops in UI thread...I would avoid it as much as possible...

Check the below link:

Lazy load of images in ListView

Community
  • 1
  • 1
Navin Ilavarasan
  • 1,271
  • 11
  • 15
  • Yes I do it in the UI thread. But as far as I saw, My guess is that People application in Htc Sense does the loading in the UI thread too (The images are shown immeadeatley when you see the contacts - without waiting it to load), So I thought to myself - there must be a way. – dor506 Jan 23 '12 at 05:43
  • I really doubt that...if that is the case with HTC....they might have already cached the images in the memory...there is no way you can be sure of the bitmap loading time...so I would advice you to move your loading part to a different thread(see my reply on how to achieve this)... – Navin Ilavarasan Jan 23 '12 at 22:38