Content Provider in Android

In my last tutorial, I have discussed the service that is the most important component in android. I would be recommended to you, please check all post related android services. Here are the details of link Service in Android Part1, Service in Android Part2 and Service in Android Part3.Now In this article, I am focusing on the share the content from different -2 ways. We will check that how many ways we can share the content to multiple apps. What are the best procedure and which is most recommended by android?Ok, Let's see how many ways we can share the data from an app to multiple apps. Actually, you can share the content many ways but some of all are not recommended by an android framework.1. Share the shared preference to other apps.2. Share the SQLite database to other apps.3. Share the internal storage files4. Share data with content provider (recommended)5. Share data by AIDL service6. Share data by TCP/IP or HTTP network communication.I have pointed some of the mechanism that we can share the content with other applications. It might be many more mechanisms also available for sharing but these are the basics that everyone is known for sharing data. The first point is here sharing the shared preference data to other apps. If we talk about the SharedPreferenece it means that we can store limited data. You can not share the huge data from this way. For a small amount of data if you want to share then its possible and make sure the database would be public for share. If you made private then is difficult to share the data, Data has stored in device sandbox that not have permission to access by any other apps. We are using SharedPreference for storing the user information.For a large amount of data, if you want to share then you can share by SQLite database. You can access the database tables and data of each table by simple SQL query. You can make a copy of SQLite DB into assets folder for access the data. Or the other one is shared by storage files. It does not need to explanation it is pretty simple. You can write the information into storage files of sd card and shared the files to other applications.Content Provider is the recommended by the Android framework to share any data from one app to other apps. By name it clear that it provide the content data to any application. Content Resolver is the mediator to help to get access the share data. By ContentResolver you can make the query on Content Provide which kind of data you want to access. It works well in the different process to share the content data with multiple apps.Even You can share data from the ADIL IPC mechanism. IPC remote mechanism is very strong to get access data from one application to other applications. Here other applications need to bind remotely. I have already focused here Service in Android Part3.You can share data from HTTP request to any other application. But it required the internet connection to get the data from the server.Let's create the App1 that maintain the database as a provider. We need to make the method synchronized to avoid the collision. It makes the method thread safe if multiple thread access the same method subsequently. Content Provider works very well in the different process. Here is uploaded the video that helps you to understand.