As mentioned before, content providers make the most sense when you want to expose the data to other applications. It is a good practice to always think of your application as part of a larger Android ecosystem and, as such, a potential provider of useful data to other applications.
To demonstrate how
content providers can be useful, we’ll create a Home screen widget.
We’re not using the term widget here as a synonym
View class, but as a
useful embedded service offered by the Home screen.
Android typically ships with a few Home screen widgets. You can access them by going to your Home screen, long-pressing on it to pull up an Add to Home Screen dialog, and choosing Widgets. Widgets that come with Android include Alarm Clock, Picture Frame, Power Controls, Music, and Search. Our goal is to create our own Yamba widget that the user will be able to add to the Home screen.
The Yamba widget will be
simple, displaying just the latest status update. To create it, we’ll
make a new
YambaWidget class that
We’ll also have to register the widget with the manifest file.
YambaWidget is the main class for our widget. It is a subclass of
AppWidgetProvider, a special system class that makes widgets. This
class itself is a subclass of
our Yamba widget is a broadcast receiver automatically.
Basically, whenever our widget is updated, deleted, enabled, or disabled, ...