Content Provider


 

  1. Simple ContentProvider
  2. CP Using AsyncQueryHandler
  3. Sharing ContentProvider Between Apps

 

1. Simple ContentProvider

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyProvider.java and add following code :

Step 5 : Open src -> package -> Create new class, DatabaseHelper.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

Step 7 : Open build.gradle(Module: app) and add following code :

ScreenShot:

simple content provider

Download SourceCode

 

 

2. CP Using AsyncQueryHandler

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyProvider.java and add following code :

Step 5 : Open src -> package -> Create new class, DatabaseHelper.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

Step 7 : Open build.gradle(Module: app) and add following code :

ScreenShot:

 using asyncqueryhandler

Download SourceCode

 

 

3. Sharing ContentProvider Between Apps
1st Application
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new Class, MyProvider.java and add following code :

Step 5 :Open AndroidManifest.xml and add following code :

 

ScreenShot:

content content2

Download SourceCode

 

2nd Application

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

content3 content4 content5 content7 content8 content9

Download SourceCode