Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Farid123
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Creating a Contact List In a fast way

Hello, 

 

I am making an application where I want to get the contacts from the address book and display them with images. So i created a custom field that accepts an image and the name and number of each contact, and then add this field to the mainscreen. But I am facing a serious problem, in case where the phone contains less than 100 contacts, everything works fine. But when the phone contains 2000 contacts, the form is taking 2 mins to load because it will take time creating 2000 different objects. Comparing it to whatsapp, it is too slow because whatsapp generates the form in 5 secs... I thought about a way to store the VerticalFieldManager containing the fields somewhere and call it everytime, but nothing worked for now.

 

Anyone can help please? I really have to find a way to make that thing faster

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Creating a Contact List In a fast way

Do you mean that you load a screen with 2000 entries? This is really huge amount of data for a mobile device and it will take you quite a bit time to scroll it.

 

Why don't you introduce some sort of paging like strategy where you load for example 100 contacts and when the users scrolls to the bottom the apps loads 100 more.

 

I am not sure how exactly this should be implemented but I believe there are many ways to do it - just don't load the whole data at once. 

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Creating a Contact List In a fast way

yes, dynamic loading should take some of the strain off.

listfields are also very efficient in displaying large numbers of objects.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
Farid123
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: Creating a Contact List In a fast way

Thanks for your reply .. I see what you are trying to say. But how can this be done? I dont know how to display only 100 and when the user scrolls display another 100.. How to make this by code? I think this is the best way to solve it since all new apps use this strategy ... Any help with that please?

Please use plain text.
New Developer
Farid123
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: Creating a Contact List In a fast way

Yeah I tried the dynamic loading but I didn't manage to successfully integrate it. Any idea how would that be done? I tried to use InvokeLater and threads to perform that .. but with no results

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Creating a Contact List In a fast way

Well I haven't really done these things for blackberry.

 

If you are using scrollable vertical manager to keep your data you might try to check when you have scrolled to the bottom (if there is some kind of event for this) and when this happens load more data.

 

If there isn't a way to know this you can just place a button labeled "Show more" at the bottom of the screen and press it when you want to load more data.

 

Note that I am just guessing here - I haven't done anything from these things. 

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Creating a Contact List In a fast way

 

how are you reading the address book? note that the enumeration offered by the contactlist class is VERY slow.

there have been some threads about this in the past. the only way to ensure fast processing is to read the full address book into an own data structure.

 

RIM uses a patricia tree which is very efficient. why they don't use it in the API is absolutely beyond me.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
Farid123
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: Creating a Contact List In a fast way

I had a quick search on the web about patricia tree and i found it useful to use. And yes i am using the enumeration thing for contacts retrieval. But i really didn't find any tutorials for using patricia tree in java... so any ideas how this can be done? If yes, this will solve the problem of enumerations and one problem will remain and is how to load 2000 contacts in a dynamic way. I am working on his right now but with no results yet!

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Creating a Contact List In a fast way

 

there is no patricia tree implementation in the RIM API, you will have to implement it yourself, most likely you will find a desktop java implementation and can port it.

 

as far as i know the board members who tackled this problem before used a low priority thread at startup to read the contacts into their own data structure. depending on the data you need you could use a lightweight custom contact or the existing blackberry contact.

 

you can use a pimlistener to react to changes when you have read the list, no need to re-read the full list then.

 

you can find a sample code on the forums which populates the addressbook of the simulator (or a device, of course) with 1k random contacts, maybe it will be helpful for performance testing.

 

i would consider not to display 2k contacts at once but to offer a search.

do some profiling or calculations depending on your data model to check if you can hold the contacts in ram or if you have to persist them and load them on demand.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
Farid123
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: Creating a Contact List In a fast way

I managed to do the work automaticaly in a background thread. The form will be loaded as an empty form and a thread will be started, in this thread i will add each contact in a separate way. On the simulator everything looks fine and the process is fast. I am waiting to test it on a real device with 2000 contacts now. 

 

I will, on the beginning of the application, load the contacts into a vector and save them in a persistent object. Then i would run a pimlistener as you said and listen for changes.

 

I think that would be the ideal solution. But the question is how to listen for changes in the address book? I searched in the APIs and i found a PIMListListener wich i dont know how to work with. Is there a simple PIMListener and any tutorial that explains how to work with it?

 

Thanks in advance for your help simon.

 

 

Please use plain text.