Open main menu

CDOT Wiki β

Changes

MAP524/DPS924 Lecture 8

1,307 bytes added, 21:33, 2 August 2015
Using an existing content provider
* Settings - Stores the device ’ s settings and preferences
The [http://developerYou should know you can use the above but we won't be writing code to query them in this course, it's much more complicated than it needs to be.android.com/intl/ja/guide/topics/providers/Instead we'll create a new content-provider-basics.html Content Provider Basics] tutorial is a little verbose and scary, but query that's kind of unavoidable with overdesigned nonsense like this.
One note about using == Implementing a content providers: there provider == A content provider looks very much like an SQLiteOpenHelper we've used in our SQLite lecture/lab. It's so similar it's easy to be confuse the two. The difference is:* Methods in an SQLiteOpenHelper are called directly in code.* Methods in a content provider are called via a content:// url. The two are such a slightly simpler way good match that most of the time if you have a content provider - you'll have an SQLiteOpenHelper paired with it. Implementing all the methods required for a content provider from scratch is too much work. So what we need to query them using managedQuerydo is: * Start from the example from the SQLite week (you can start with your lab).* Add a class extending ContentProvider.* Implement the required methods (Android Studio will help with all this) but .* Our ContentProvider will use the query method from the SQLiteExample and do little else.* Note that function has been deprecated the ContenProvider is mentioned in the manifest in the <provider> tag. == Implementing a content resolver == A content resolver is just the client for the content provider. To demonstrate how this system is supposed to work we'll have the content resolver in a different appliction. * Create a brand new app, called "Client".* Add a button and a callback.* When the button is pressed - send a trivial query to the content provider. We only have time to scratch the surface of this topic so you shouldnwe won't use bother with all the different parameters, but it in new code's important for us to know generally how a content provider works and is implemented.