Now that we've looked at the source code for HobbitActivity, we'll examine
the source code for HobbitOps, which is a helper class that consolidates and
simplifies operations on the Hobbit provider.
There's several fields to find in the HobbitOps class including a field
that keeps track of the reference to the HobbitActivity.
A field that keeps track of a cursor retaining the results to a query so
the display can be updated automatically after a run time configuration change
occurs.
We also keep track of a field for a content resolver that used to access
the underlining hobbit provider and then finally we have the field
called all races that keep track of all the races in the program.
Dwarves, hobbits, humans and so on.
Let's take a look at the various methods.
Here's the constructor.
It's used to get a reference to the content resolver for
this particular app as well as the hobbit activity to stash it away.
Here is the insert method.
As you can see this method is really a wrapper around the insert method that's
defined by a content resolver.
Which we'll take a look at in a second, and
what this does is it takes a character's name and a character's race.
Sticks those into the content values object and then goes ahead and
inserts that at the particular content URI that
represents the database that we're using here in SQLite.
Here's the insert method itself.
As you can see, this simply uses the content resolver insert method to
insert the content values at that URI.
Down here we see a bulk insert,
where we take an array of characters of a particular race.
And we go ahead and we create an array of content values.
And we insert each of the characters into the array in the appropriate place, and
then we call the bulk insert method.
Here is bulk insert.
As you can see bulk insert simply forwards to the content resolver to insert
the array of content values at that URI,
which indicates which table element we're talking about here.