Android “Content Provider” Frequently Asked Interview Questions Part 4 of. N

I Have taken most of the questions from people’s interview reviews from glassdoor and combining them in one place.

1.What is the content provider?

Ans: A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.

2.What is a content Resolver?

Ans: The Content Resolver is the single, global instance in your application that provides access to your (and other applications’) content providers. The Content Resolver behaves exactly as its name implies: it accepts requests from clients and resolves these requests by directing them to the content provider with a distinct authority. To do this, the Content Resolver stores a mapping from authorities to Content Providers. This design is important, as it allows a simple and secure means of accessing other applications’ Content Providers.

The Content Resolver includes the CRUD (create, read, update, delete) methods corresponding to the abstract methods (insert, query, update, delete) in the Content Provider class. The Content Resolver does not know the implementation of the Content Providers it is interacting with (nor does it need to know); each method is passed a URI that specifies the Content Provider to interact with.

3.Cursor in content provider?

Ans: A cursor is an object by which we get data from the content resolver.

Provides random read-write access to the result set returned by the CursorLoader

4.What kind of data can be shared through the content provider?

Ans: No Restriction on data.

5.Methods of the content provider(CRUD)?


onCreate() This method is called when the provider is started.

query() This method receives a request from a client. The result is returned as a Cursor object.

insert()This method inserts a new record into the content provider.

delete() This method deletes an existing record from the content provider.

update() This method updates an existing record from the content provider.

getType() This method returns the MIME type of the data at the given URI.

6.What is content URI?

Ans: To query a content provider, you specify the query string in the form of a URI.


prefix->This is always set to content://

authority->This specifies the name of the content provider, for example, contacts, browser, etc. For third-party content providers, this could be the fully qualified name

data_type->This indicates the type of data that this particular provider provides. For example, if you are getting all the contacts from the Contacts content provider, then the data path would be people and URI would look like thiscontent://contacts/people

id->This specifies the specific record requested. For example, if you are looking for contact number 5 in the Contacts content provider then URI would look like this content://contacts/people/5.

7.In which thread content provider runs?

Ans: Main thread.

8.What is loader?

Ans: The Loader API lets you load data from a content provider or other data source for display in an FragmentActivity or Fragment.

Loaders solve these problems and include other benefits. For example:

  • Loaders run on separate threads to prevent janky or unresponsive UI.
  • Loaders simplify thread management by providing callback methods when events occur.
  • Loaders persist and cache results across configuration changes to prevent duplicate queries.
  • Loaders can implement an observer to monitor for changes in the underlying data source. For example, CursorLoader automatically registers a ContentObserver to trigger a reload when data changes.

9.What is LoaderManager?

Ans: An abstract class associated with an FragmentActivity or Fragment for managing one or more Loader instances. There is only one LoaderManager per activity or fragment, but a LoaderManager can manage multiple loaders.

To get LoaderManager, call getSupportLoaderManager() from the activity or fragment.

To start loading data from a loader, call either initLoader() or restartLoader(). The system automatically determines whether a loader with the same integer ID already exists and will either create a new loader or reuse an existing loader.

10.What are LoaderCallbacks?

Ans: This interface contains callback methods that are called when loader events occur. The interface defines three callback methods:

  • onCreateLoader(int, Bundle) - called when the system needs a new loader to be created. Your code should create a Loader object and return it to the system.
  • onLoadFinished(Loader<D>, D) - called when a loader has finished loading data. Typically, your code should display the data to the user.
  • onLoaderReset(Loader<D>) - called when a previously created loader is being reset (when you call destroyLoader(int) or when the activity or fragment is destroyed and thus making its data unavailable. Your code should remove any references it has to the loader's data.

This interface is typically implemented by your activity or fragment and is registered when you call initLoader() or restartLoader().

11.What are AsyncTaskLoader and CursorLoader?

12.What is RestartLoader loader?

Ans: To discard your old data, you use restartLoader().

Give a clap if you like the content.




Senior Android App Developer | Startup | Product base | Java | Kotlin | MVVM | Architecture components | Android Blogger

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Easy and performant GraphQL over REST

Getting past CORS Through the Backdoor

Security bouncer behind a rope

How to recover ScreenFlow file after crash

What is Linux and why you should be using it

An Overview of AWS CodeCommit

Patterns for Continuous Integration with Docker on Travis CI

Debug Your Python Code like a Master

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aalishan Ansari

Aalishan Ansari

Senior Android App Developer | Startup | Product base | Java | Kotlin | MVVM | Architecture components | Android Blogger

More from Medium

Automate your Android build code

How to perform search using channel for Paging 3

Run App using Wi-Fi (Android Studio Update)

MVP Architecture with Example in Android