How to run cordova.contacts in the background

On the load of a cordova / ionic app we are bringing in the contacts on the device for use in the app. However, in some cases this can take 10-15 seconds or more on large address books and prevents the initial application view loading until it completes.

Is there a way to run the ‘import’ of the address book in the background / as a separate thread that will not delay the load of the main app screen/other screens/stop the app being usable?

I’ve searched for a plugin or some code but they tend to only worry about android / are not multi platform.

Javascript is sequentially executed, therefore, no threads exist on this point. You could however create a cordova plugin that runs the collection of contacts on a seperate java thread… Which indeed, is another android-only suggestion.

To keep things in javascript, I would suggest starting a page that says something like “wait a moment, we are loading your contacts” for example. So the user knows what he’s waiting for. Besides that…In pure javascript, you can’t really have another “thread”. (Even async calls are not really another thread, they are just different processes that execute after another… Would still block your app if you used it.)

are you loading the adressbook every app start or only the first time?
are the contacts on the first view of the app?

what i did in my app as soon as the user enters the settings view i will load the contacts. so if he clicks on import the contacts are already loaded.

1 Like

Alas we need to do this on each app load in the background to check against another set of hashed information. I fear we will need to work out how to add this in the native SDK and then pass the information between the two.

We need to load it on every app start to update contacts automatically.

then i dont see an JS option only with native.

would it be a option to load it the first time save them in a DB.
and when the app starts it will show the contacts form DB. and then you load the contacts form adressbook and then you compare?

1 Like

Yeah, storing contacts in a local DB like webSQL or indexedDB sounds the best way for me, performance wise. It will become a “lazy-comparison” but that’s just about fine really. Depending on your case @fox I would consider this, I can’t really think about a situation where you can’t use this.

We are already doing that but we need to check for new data on each load so still have to load everything in again, and as such get the delay again.

So, anyway to do this in the background or is there an easy way to do a ‘new records / changed records only’ from the address book?

Hi Fox,
Did you find a solution to this issue? How did you proceed?

We are facing a similar dilemma … Would love to hear your response…

You can use this plugin