Intent vs Content Provider in android

I am new to Android application development and studying the main Android components, I got confused between intentions and the content provider, since both of them are used to send data from one application / component to another application / component. In case of intent, we can send data using a kit or additional components, which is why we use content providers. Can someone please explain this to me as an example.

Also, we can access the database in android only with the help of the content provider, and is this the only reason we use content providers?

+6
source share
2 answers

both are used to send data from one application / component to another application / component

Not really.

There are four components to Android:

  • Activity
  • Service
  • BroadcastReceiver
  • ContentProvider

An Intent not one of them. Intent involved when we start an action, start or associate with a service, or send a broadcast. However, comparing Intent with a ContentProvider akin to comparing with a shovel with a boot, claiming that both can be used to carry dirt. Although this is true, a boot is usually loaded when loading dirt, but the actual means of transporting the dirt are handled by something else, such as a wheelbarrow.

In case of intent, we can send data using a kit or additional components, which is why we use content providers.

We often use different tools for different circumstances. For example, it will be difficult for you to transfer water to the fishing net.

Each of the four components has a different role, especially with regard to interprocess communication (IPC):

  • Activity controls the main part of our user interface, including launching actions from other applications (or launching one of our actions by other applications)

  • A Service exists for longer operations that are logically separate from the user interface, including working with services that are implemented by other applications (or having other applications for working with the services you publish)

  • A BroadcastReceiver is a publication / subscription exchange system that allows you to send messages to arbitrary subscribers or subscribe to messages from arbitrary senders across the borders of the process.

  • A ContentProvider designed for mass data transfer, whether in the form of a database style structure (rows and columns) or as a stream, especially for working with other applications

Also we can access the database in android only with the help of the content provider

No. After all, if that were the case, it would be impossible to access the database. A ContentProvider does not appear by magic. It must be written by a programmer. If the ContentProvider could only access the database using the ContentProvider , we would have a problem.

Is this the only reason we use content providers?

No. Besides offering a database-style API, ContentProvider can also publish a stream. This is important for obtaining arbitrary data between applications, such as an email client that makes PDF attachment available for viewing PDF files.

+9
source

Intents is a messaging architecture for sending / receiving transactional commands and data. Content providers provide an abstract storage interface for creating, updating, deleting, and synchronizing.

+2
source

All Articles