Android Question [SOLVED] ContactUtils - Slow or Normal?

Sagenut

Expert
Licensed User
Longtime User
Hi Everyone.
I am using the ContactUtils Class to read contacts from phone.
This is the code:
B4X:
For Each c As cuContact In cu.FindAllContacts(True)
      bmp = cu.GetPhoto(c.Id)
      If bmp.IsInitialized Then
             CompilaContatti(c.Displayname)
       Else
             bmp = LoadBitmap(File.DirAssets,"felice.png")
             CompilaContatti(c.Displayname)
       End If
Next
It needs something like 6-7 seconds to retrieve 208 contacts, with the app installed on phone from apk.
Is it normal or is it too slow?
The Sub CompilaContatti perform the creation of a panel with an imageview (filled with bmp) and a label (filled with c.Displayname) for every contact and then the panel is added to a XCustomListView.
Thanks for Your attention.
 

Star-Dust

Expert
Licensed User
Longtime User
I have faced this problem a few years ago.
If you request the list of contacts without images is fast, while if you request the image of the profile everything becomes very slow, especially in older devices.

The solution is to load the list of contacts and with an asyncron method add the images, which can also be a timer.
WhatsApp uses just this method, in fact sometimes you notice that the images appear progressively.

You can get this with a ScrollView or custom ListView.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Your suggestion that I can give you is that this work of loading the asynchronous images does not have to do it at the time of the app, so when you open the contact list already a part of the images have been loaded the populated list.

Every time you open the panel containing the list then start an update of the images, they will probably be rarely updated 1 or 2 at most, so you will not even notice that there was an update because you will not see any lag
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I think that the chances that the user update his phone contacts list while using my app are very very rare.
So the second option is even to make the contact list to be populated at the app startup while the list is still invisible.
In this way the lag would be noted only at the first time that the list come populated because before it's needed to request the Permission.
To solve even this I could ask all the Permissions that my app can need at the startup.
But my idea was to ask the various Permissions only when the user trigger something that need to have a Permission.
Updating the list would make me to reload it at all having the lag anyway because for now I didn't checked how to add items in the middle of an existing list.
Now I have a clearer situation of how I can solve my actual problem.
Then I can always improve it with better methods in the future while gaining experience.
Thanks for the advices.
 
Upvote 0
Top