ggarber
ggarber

Reputation: 8360

Best practice to show android contacts + phone numbers

What is the best approach from a performance perspective to show a ListView with contacts and their phone numbers?

Upvotes: 7

Views: 1573

Answers (4)

Erdal
Erdal

Reputation: 1502

I think CursorAdapter is the best solution.

Also make sure you watch this video http://www.youtube.com/watch?v=wDBM6wVEO70 It talks about optimizations that in my opinion are necessary to make your list scroll smoothly.

Upvotes: 0

Edison
Edison

Reputation: 5971

I think this would depend on three factors:

  1. How many contacts are we talking about here?
  2. How much time does it take to load each contact? (E.g. do you have a very complicated view that needs to be inflated or do you fetch contact images/etc that requires any network I/O?)
  3. How much contacts are showing to the user at once?

Your solution one would fit most of the cases though the second solution offers some advantages as well:

Solution 1:

Advantage:

  1. Delayed view inflation in a "view as you go" can perform well when it's fast enough to inflate the views without any noticeable UI glitches.

Disadvantage:

  1. If your contacts associate with a lot of data and requires some complicate inflation, you might notice a delay.

  2. Less flexible and extensible comparing to solution 2. As discussed below.

Solution 2:

Advantage:

  1. You have control of all the steps, so you can easily simulate it just as easy as one, but adding things might be easier: searches through whole memory, custom sorting through the array, etc. they work better when you have everything queried to an array that's already there. Or if you want to do custom loading later, or adding some more data regarding the contacts that require some more processing (say network I/O), it might be slightly easier than cursor adapter.

Disadvantage:

  1. Execution: this is not the text-book way to do it. making things more custom will need you to handle all the threads well and handle the initial appearance well. Make sure it scales.

So yea, depending on what exactly are you are working on, choose the appropriate one.

Upvotes: 1

Mak
Mak

Reputation: 1063

I think http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/ will be an option. Where you can find all of the facility you want...

Upvotes: 0

matiasnj
matiasnj

Reputation: 604

In my opinion a mix solution should be better. Why this? Because you don't know or it's suppose that in most of contexts you cannot know about how and how many contacts your application will need to list. An also how many contacts are stored in the phone. If we know both answers, surely we can take the most approach solution.

So I suggest you to first bring a fix number of contacts using an in-memory array in a background thread, for example the first 20. Also if you consider that your app will perform more than one request to this service.. it will be awesome to use a sort of caching. The worst approach should be to call again and again the contacts service. Then for a request for contact #21 you can bring next 20 and so on.

So you can use the advantages of both worlds, and minimize the disadvantages too. Always depends on the application and the context that we are talking about.

Upvotes: 1

Related Questions