Getting all contacts is very slow

1,202 views
Skip to first unread message

Mark Murphy

unread,
Sep 8, 2011, 10:59:18 PM9/8/11
to phonegap
Hi All,

Using Android, I run the following code to get all the contacts on the
phone. On a device with 1k contacts, it takes about 3 minutes to from
the time of the request until the success callback runs. From the
logcat it appears that SQL Lite is thrashing about. If I filter for
just records with 'Bob' (8) the app is responsive. I read about some
limit of 1mb for a SQL result though I've not dove into the details.

Is there a workaround? I need to populate list with all contacts. Just
name and few details for each. Thanks!

Note: I'm watching the console logging with Weinre at
debug.phonegap.com.


if (havePhoneGap) {
// this.contactStore.load();
console.log('Test contacts find');

navigator.service.contacts.find(
//Fields
//['id', 'name', 'emails', 'phoneNumbers',
'addresses'],
['name'],
//Success function
function(deviceContacts) {
console.log("Found contacts success ");
//loop over deviceContacts and create Contact
model instances
var contacts = [];
console.log("Found contacts " +
deviceContacts.length);
for (var i = 0; i < deviceContacts.length; i++) {
console.log(deviceContacts[i].name.givenName);
}
},

//Error function
function (e) {
console.log('Error fetching contacts');
},

//Options
{multiple: true, filter: ''}
);

}

Giacomo Balli

unread,
Sep 9, 2011, 4:18:41 AM9/9/11
to phonegap
loading 1k+ contacts (each having details) in 3min using a nitroless
javascript engine.... I?m afraid that's not too bad.
I understand you'd want more but would have no clue a part from
filtering.

Simon MacDonald

unread,
Sep 9, 2011, 9:43:20 AM9/9/11
to phon...@googlegroups.com
Yeah, a lot of the time is spent loading the contacts out of the SQL
DB and building up an array of JSON Objects. The mapping is not as
easy as one would think and if anyone can make the process faster I
will gladly work with them to integrate the code.

Simon Mac Donald
http://hi.im/simonmacdonald

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>

Mark Murphy

unread,
Sep 9, 2011, 12:00:15 PM9/9/11
to phonegap
Thanks Giacomo and Simon,

That sheds some light. This is an invite your friends option. I was
thinking of a checklist of all your friends, but having the user type
in 3 letters of each name to add to the invite list may be the best
route.

Simon, I see your name in the forum a lot. Are you one of the main
contributors to the Android version of PhoneGap? If so, good on you!
If there's a description of how to get the dev environment set up to
make the changes you describe? I tried previously to set up the
phonegap source but ran out of time. I'm a long time dev but pretty
new to Java and Android.

Mark

Giacomo Balli

unread,
Sep 9, 2011, 1:00:38 PM9/9/11
to phonegap
perhaps you're trying to reinvent the wheel.
I'm pretty sure you can have a simple modalView where the user picks
the contacts (like for pictures) without you having to import
everything.

Simon MacDonald

unread,
Sep 15, 2011, 3:24:16 PM9/15/11
to phon...@googlegroups.com
Hey Mark, 

Too many emails. If you want to build directly from phonegap-android try following this wiki page:


It's pretty easy just to clone the src from github and run "ant jar" to build the .jar/.js combo.

You might just want to use the native contact picker and make your life easier:


Simon Mac Donald
http://hi.im/simonmacdonald



--
Reply all
Reply to author
Forward
0 new messages