I am trying to learn the content provider implementation and how it works. I tried the sample notepad application in Android SDK and everything is working fine. I am able to create new notes and save them and edit them.
I tried changing this content provider to custom implementation. This is working fine. But I dont understand the below implementations
1) why is the Notepad.java defined two times once within the folder “com.example.android.notepad” and then within “com.google.provider”.
2) How is the intent type “content://com.vinod.provider.NotePad/notes” going to the list and “content://com.vinod.provider.NotePad/notes/2” going to the edit activity? how is this controlled?
3) in the manifest I see mime type like “vnd.android.cursor.dir/vnd.google.note”. what does the vnd.android.cursor.dir and vnd.android.cursor.item stands for. And what is “vnd.google.note”
Can some one please explain me these questions. Thank you for your time and help.
1) Two Files
They are two different classes — com.example.android.notepad is a class that implements the application. com.google.provider.notepad is a class that implements the ContentProvider.
The application provides the user interface, the ContentProvider provides data storage.
Looking at This link to the Notepad ContentProvider example, its’ naming is much clearer.
2) URI Matching
Referencing NotepadProvider.java:
UriMatcher takes a list of patterns.
NotePad.AUTHORITYis the base of the content URI."notes"is one pattern to match, and the enum NOTES is returned."notes/#"is one pattern to match, and the enum NOTE_ID is returned.Is the pattern for making a decision to run different code based on URI
3) MIME types
MIME types are optional. You probably don’t need to do anything with them.