Git Product home page Git Product logo

resolver-vs-loader's Introduction

ContentResolver Vs CursorLoader Speed Test

While developing my app DCM I used both the ContentResolver and the CursorLoader to fetch contacts from the mobile. The ContentResolver is a class that provides applications access to the content model. The CursorLoader is a loader object that queries a ContentResolver for data. In my trials I noticed that the ContentResolver is much faster.

This application compares the execution time of both methods in fetching contacts. The library is modified and extended from my Mobile-Contacts-Library which solely used the ContentResolver to fetch contacts:

The following images are results of a test performed on the simulator. Real life tests on my Samsung tablet S2 showed that the ContentResolver was almost twice faster than the CursorLoader.

ย 

The demo app for this library is available on Google Play:

Get it on Google Play

Installation

In the app manifest file add this permission:

<uses-permission android:name="android.permission.READ_CONTACTS" />

In the app build.gradle add the following:

a. Add JitPack repository at the end of repositories

repositories 
{
   maven { url 'https://jitpack.io' }
}

b. Add the dependency

dependencies 
{
     compile 'com.github.Jagerfield:Resolver-Vs-Loader:v1.3'
}

How to use?

You can use this library to fetch contacts using either one of the methods or both:

Fetch contacts using ContentResolver

  new ImportContacts(getActivity(), new ImportContacts.ContentResolverCallback() 
  {
      @Override
      public void getMobileContacts(ArrayList<Contact> contacts)
       {
           if (contacts != null)
             {
                //Write your code here
             }
        }
  });
  

Fetch contacts using CursorLoader

  new ImportContacts(getActivity(), new ImportContacts.CursorLoaderCallback() 
  {
      @Override
      public void getMobileContacts(ArrayList<Contact> contacts) 
       {
           if (contacts != null)
             {
                //Write your code here
             }
        }
  });

Privacy Policy

This app sample will request the follwoing permission below which require user approval and is used for demonstration purposes only. No data is shared or used outside this app.

  • android.permission.READ_CONTACTS

resolver-vs-loader's People

Contributors

jagerfield avatar

Stargazers

Wade avatar

Watchers

James Cloos avatar

Forkers

morristech

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.