Why does this code run so slow?

Pops

Member
Licensed User
Longtime User
B4X:
Dim list1 As List
    list1 = Contacts2.GetAll(True, False)
Dim listOfContacts As List
        listOfContacts.Initialize
For i = 0 To list1.Size - 1
Dim c As Contact
    
                            c = list1.Get(i)
                            
                        If c.DisplayName.IndexOf("@") = -1 Then
                            
                            
                            Dim m As Map
                                m = c.GetPhones
                                    
                                    If m.Size > 0 Then
                                    
                                    
                                    
                                    For CellHome = 0 To m.size-1
                                    
                                 listOfContacts.Add(c.DisplayName)
                              
                                    Next
                                    
                                    End If
                                    
                                    
                            listOfContacts.Sort(True)
                        End If
Next
   Dim res As Int
      res = InputList(listOfContacts, "Choose contact", -1)

If I eliminate this part:
B4X:
Dim m As Map
                                m = c.GetPhones
                                    
                                    If m.Size > 0 Then
                                    
                                    
                                    
                                    For CellHome = 0 To m.size-1
                                    
                                 listOfContacts.Add(c.DisplayName)
                              
                                    Next
                                    
                                    End If
Then it brings up the contact list very rapidly. Of course then it won't show the contacts that have multiple phone numbers.
Is there a way to optimize this? It seems to run the same speed whether I show contact phone numbers, label the contacts (cell, home, work, etc.) or just run it showing only contact names.
 

Pops

Member
Licensed User
Longtime User
I press a button and the contact list pops up. If a contact has both mobile and home numbers, for instance, that contact name is listed twice.
Or... if I click on a name that has more than one number, I will have the option to choose one of them.
I think something like that is possible, at least I hope so.
 
Upvote 0

Pops

Member
Licensed User
Longtime User
Sorry for all the questions. once I click on my contact, how do I work with that contact with maps and GetPhones???
 
Upvote 0
Top