04-19-2011 04:16 AM
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
04-19-2011 04:42 AM
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.
04-19-2011 04:50 AM
yes, dynamic loading should take some of the strain off.
listfields are also very efficient in displaying large numbers of objects.
04-19-2011 04:50 AM
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?
04-19-2011 04:55 AM
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
04-19-2011 04:57 AM
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.
04-19-2011 05:01 AM
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.
04-19-2011 05:23 AM
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!
04-19-2011 05:44 AM
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.
04-19-2011 07:39 AM
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.