In the last article, we talked about using Linkify to turn wiki words (those that match a regular expression we defined) into a content: URI and defining a path to data that matched a note belonging to that wiki word. As an example, a matching word like ToDoList
would be turned into a content: URI like content://com.google.android.wikinotes.db.wikinotes/wikinotes/ToDoList
and then acted upon using the VIEW action from the Linkify class.
This article will examine how the Android operating system takes this combination of VIEW action and content: URI and finds the correct activity to fire in order to do something with the data. It will also explain how the other default links created by Linkify, like web URLs and telephone numbers, also result in the correct activity to handle that data type being fired. Finally, this article will start to examine the custom ContentProvider that has been created to handle WikiNotes data. The full description of the ContentProvider and what it does will span a couple more articles as well, because there is a lot to cover.
The Linkify-calls-intent Workflow
At a high level, the steps for Linkify to invoke an intent and for the resulting activity (if any) to handle it looks like this:
- Linkify is invoked on a TextView to turn matching text patterns into Intent links.
- Linkify takes over monitoring for those Intent links being selected by the user.
- When the user selects a link, Linkify calls the VIEW action using the content: URI associated with the link.
- Android takes the content: URI that represents the data, and looks for a ContentProvider registered in the system that matches the URI.
- If a match is found, Android queries the ContentProvider using the URI, and asks what MIME type the data that will be returned from the URI is.
- Android then looks for an activity registered in the system with an intent-filter that matches both the VIEW action, and the MIME type for the data represented by the content: URI.
- Assuming a match is found, Linkify then invokes the intent for the URI, at which point the activity takes over, and is handed the content: URI.
- The activity can then use the URI to retrieve the data and act on it.