Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.Jagerfield:Resolver-Vs-Loader:v1.3'
}
dependencies {
implementation("com.github.Jagerfield:Resolver-Vs-Loader:v1.3")
}
<dependency>
<groupId>com.github.Jagerfield</groupId>
<artifactId>Resolver-Vs-Loader</artifactId>
<version>v1.3</version>
</dependency>
libraryDependencies += "com.github.Jagerfield" % "Resolver-Vs-Loader" % "v1.3"
:dependencies [[com.github.Jagerfield/Resolver-Vs-Loader "v1.3"]]
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.
<img src="https://github.com/Jagerfield/Resolver-Vs-Loader/blob/master/msc/ContentResolver.png" width="240"> <img src="https://github.com/Jagerfield/Resolver-Vs-Loader/blob/master/msc/Cursor%20Loader.png" width="240">
The demo app for this library is available on Google Play:
<a href='https://play.google.com/store/apps/details?id=jagerfield.ContentResolverVsCursorLoader'><img alt='Get it on Google Play' src='https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png' width="150" height="60"/></a>
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'
}
You can use this library to fetch contacts using either one of the methods or both:
new ImportContacts(getActivity(), new ImportContacts.ContentResolverCallback()
{
@Override
public void getMobileContacts(ArrayList<Contact> contacts)
{
if (contacts != null)
{
//Write your code here
}
}
});
new ImportContacts(getActivity(), new ImportContacts.CursorLoaderCallback()
{
@Override
public void getMobileContacts(ArrayList<Contact> contacts)
{
if (contacts != null)
{
//Write your code here
}
}
});
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.