The notion of the Content Provider is central to getting things done in an Android application. This is the mechanism used to expose many of the device's interpretation resources for retrieval as well as update: Contacts, media store, bookmarks, phone-call log, as well as so on. Its tough to find an interesting Android app which doesnt possibly make use of or exercise (or both) the Content Provider.
Theres nothing magical or terribly startling about Content Providers - we residence them by Url, question them with SQL, as well as iterate them with the Cursor. They do what they say they do as well as get out of the approach as well as theyre easy to emanate as well as use. But theres the usual anti-pattern, the approach to injustice them which can potentially get your app in to trouble, as well as may be weve made it the small too easy.
The Content Providers which the Android horizon gives we have been described in the SDKs android.provider package summary. For many of them, the horizon provides supporter classes of one sort or another, to help automate usual chores as well as provide symbolic names for utilitarian constants.
The problem is, there have been more Content Providers in the complement than have been documented in which package, as well as while we can make use of them, we probably shouldnt. Theyre there since the little of the Google-provided apps make use of them internally to entrance their own interpretation resources. Because Android is an open-source project, its easy enough to find them only by using bombard commands similar to find as well as grep over the source tree.
(By the way, acid the source tree similar to this is an excellent idea, something which probably every serious developer does regularly. Not 100% certain of the most appropriate approach to write formula to arrangement the record from the Contacts database? Go ahead, have the demeanour at how the built-in app does it; even better, steal the little code; its perfectly legal.)
Back to Content Providers. For example, theres one inside the built-in Messaging (A.K.A. texting or SMS) app which it uses to arrangement as well as search your history. Just since its there doesnt meant we should make use of it. The Android group isnt earnest which itll be the same in the next release or even which itll be there in the next release.
Its worse than that; someone could boat an Android device formed upon the current SDK which follows all the manners but has its own enhanced messaging duplicate which doesnt occur to have such the Content Provider. Your app will break upon such the device as well as itll be your fault.
So, go ahead as well as demeanour at the undocumented Content Providers; the formula is full of great ideas to learn from. But dont make use of them. And if we do, when bad things occur youre flattering well upon your own.
National Car Rental
Tidak ada komentar:
Posting Komentar