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:

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:

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