Creating Simple Content Provider with Real-time Scenario

Hey guys, if you are here. Then i can expect that you have already gone through my blog about Basic concepts of Content Provider. Which gives a brief understanding of content provider and its key concepts.

Now we are going to explore content provider API much deeper. Here we are going to create a Simple Content Provider in our APP.

Let say we are creating an application of tour and travel guide, hear user can search about tourist places and get information about that place. Suddenly we thought, why not to generate some revenue by sharing data of our app explored by user. So our business team suggested to share searched cities and places name's with other app's that having Train, Flight, Bus Hotel booking system. So that they show precise notifications, offer's to user for that places.

Everything is done from business point of view. Then we discussed our tech team about feasibility of this task. They said, this is not a big deal we have to create a Content Provider which let other app to access our data. This can be done. Woooh!!!

So guy's this is just one simple scenario when we need to create a content provider.

Now let's walk through API and steps of creating Content Provider.

Our first step, to create a concrete class to extend Content provider and Implement our business logic.

PlacesProvider.java
public class PlacesProvider extends ContentProvider{
    /**
     * This method is called when the provider is started.
     * @return
     */
    @Override
    public boolean onCreate() {
    show...

As you can see when you extend ContentProvider it will implement some of its methods. This method used to perform CRUD operation by app's. You can see comment over these method for understanding purpose.

So Content Provider is the upper layer or you can say interface between you app data and other app.
But after this layer you SQLite or other structured/File data handler resides.

So our next step is to create DatabaseHandler. This class is similar class as we create DatabseHelper class normally in our app.



Comments

Popular posts from this blog

Software Design Principles (SOLID)

Draw Over Screen App Example Android

Sync Adapter Overview