Skip to content

Commit

Permalink
Run getAll() in a background thread on Android to reduce performance …
Browse files Browse the repository at this point in the history
…impact
  • Loading branch information
MattDavies committed Nov 14, 2016
1 parent 8011d0c commit 7c2345d
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
Expand All @@ -30,14 +31,19 @@ public ContactsManager(ReactApplicationContext reactContext) {
* queries CommonDataKinds.Contactables to get phones and emails
*/
@ReactMethod
public void getAll(Callback callback) {
Context context = getReactApplicationContext();
ContentResolver cr = context.getContentResolver();
public void getAll(final Callback callback) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
Context context = getReactApplicationContext();
ContentResolver cr = context.getContentResolver();

ContactsProvider contactsProvider = new ContactsProvider(cr, context);
WritableArray contacts = contactsProvider.getContacts();
ContactsProvider contactsProvider = new ContactsProvider(cr, context);
WritableArray contacts = contactsProvider.getContacts();

callback.invoke(null, contacts);
callback.invoke(null, contacts);
}
});
}

/*
Expand Down

0 comments on commit 7c2345d

Please sign in to comment.