Creating Intent Filters
Up to now, the focus of this book has been on activities opened directly by the user from the device’s launcher. This, of course, is the most obvious case for getting your activity up and visible to the user. In many cases it is the primary way the user will start using your application.
However, the Android system is based upon lots of loosely‑coupled components. What you might accomplish in a desktop GUI via dialog boxes, child windows, and the like are mostly supposed to be independent activities. While one activity will be “special”, in that it shows up in the launcher, the other activities all need to be reached… somehow.
The “how” is via intents.
An intent is basically a message that you pass to Android saying, “Yo! I want to do… er… something! Yeah!” How specific the “something” is depends on the situation – sometimes you know exactly what you want to do (e.g., open up one of your other activities), and sometimes you don’t.
In the abstract, Android is all about intents and receivers of those intents. So, now that we are well‑versed in creating activities, let’s dive into intents, so we can create more complex applications while simultaneously being “good Android citizens.”
What’s Your Intent?
When Sir Tim Berners‑Lee cooked up the Hypertext Transfer Protocol – HTTP – he set up a system of verbs plus addresses in the form of URLs. The address indicated a resource, such as a Web page, graphic, or server‑side program. The verb indicated what should be done: GET to retrieve it, POST to send form data to it for processing, etc.
Intents are similar, in that they represent an action plus context. There are more actions and more components to the context with Android intents than there are with HTTP verbs and resources, but the concept is still the same.
Just as a Web browser knows how to process a verb + URL pair, Android knows how to find activities or other application logic that will handle a given intent.
Дата добавления: 2015-05-16; просмотров: 775;