Explicit intents are typically used to interact with components that reside in the same application. It's a very popular programming style that's used frequently in Android applications so we'll show it here on our examples. And it's made possible by the fact that the various methods like set component and set class return in intent so they can be chained together. This is called, a fluent interface programming style. Notice how all these various methods are chained together. And then we're setting the class to be this component and the Java class for that particular component implementation. In this case we're creating a new intent with a default constructor, we're passing in a text string name for the component name. Here's another example using a somewhat different coding style. As well as indicate the class for the component that you're making the explicit intent for. You can say new intent passing in the this parameter for the object that's being called which is often an activity. Note again that the chain here indicates the tight coupling between the activity in the service that uses an explicit intent. This diagram for example shows that activity one is sending an explicit intent to Service two. A named, or so called explicit intent, is sent to an instance of a designated class. The name element identifies the component that can receive an intent, the component name is optional. We'll first start by looking at the Android intent structure for the name element. This part of the lesson shows some code snippets for building intents. Some of the elements we'll discuss are of interest to the components that receive the intent, other elements are of interest to the Android system itself. This part of the lesson builds upon the discussions we had in the previous part, to allow you to understand the details of Android's intent structure. Welcome to part 2 in a lesson on Elements of an Android intent.
0 Comments
Leave a Reply. |