Android Certification Training Course
- 65k Enrolled Learners
- Weekend
- Self Paced
In our last Android Tutorial, we discussed the Activity component of Android application. This Android tutorial here covers the basics of the next building block, i.e. Android Intent.
If you want to get a live lecture covering the basics of Android development for free, sign up here!
Watch this video to get an overview of Intent.
In our Android tutorial covering fresher interview questions, we had explained the usage of Intent in Facebook with the following example:
Suppose you are on the news feed screen (which is one Activity), and want to view a pic posted by our friend. When you click on the photo, the intent associated with the click event of photo is fired which communicates the message, and the Photo page opens (which is a new Activity).
So, we assume that you understand a little about Android Intent. This Android tutorial would discuss a few deeper concepts associated with the topic.
To simplify this, let us once again take a similar example of the Facebook app.
The example below assumes that you are on the Photo Gallery Activity, and want to view a specific photo (which would open in its own activity). This is how the Intent associated with the click photo event is fired:
Sometimes, one can define Intent to notify the Android system about the occurrence of an event. This is precisely what happens in case of Broadcast Receivers (for instance, intent is defined to communicate battery low notification to the user).
Let’s take another example of the Domino’s Pizza app. Let us suppose you are viewing the Menu Screen (Activity) of the application, and want to select a pizza. When you select the Mexican Wave pizza, and click on Customize button, another screen (activity) pops up, where you can further specify the size of the pizza, type of crust you want etc. Here, the Click Action (Select Pizza Intent) on the Menu communicated the message to open the new popup window (new activity).
Simple; right! Let us get a little into the details in the next part of the Android tutorial:
If you wish to make a dinner date with your friend, and are conveying the information through a messenger, you ought to give the messenger details like the name of your friend and the specifics of the desired meeting (time, place, etc.). Not having given the specifics of the meeting to the messenger, you cannot just assume that they would figure out what to do. You might write all this information on a piece of paper for the messenger’s reference.
Similarly, as intent is a message, the complete information that it wants to convey must be stored somewhere, right! Intent Object takes care of that.
Intent Object contains all the information that the ‘Intent’ means to convey:
Delving further, Intents can be Explicit or Implicit.
An Explicit Intent is exactly what it means literally: an “explicit intention” to perform an action. Simply put, in this case, we define explicitly the Android component (Activity, Service or Broadcast Receiver) that needs calling.
Sample Code 1: Explicit Intent sample code
Here we do not specifically define the component that needs to be called. However, the Intent contains enough information to direct the system to fetch the correct one.
Sample Code 2: Implicit Intent sample code
Above implicit intent tells the Android System to view the Web Page provided in the URI.
Because of the arbitrary nature of Implicit Intents, the system uses a process called Intent Resolution to map them correctly. The system does this by matching the Intent description with the default descriptions in the system.
Intent Object, defined earlier comes into play here. The Intent Resolution compares the contents of Intent Object against the Intent Filters. (Intent Filters are associated with the different Android components, and can receive Intent. Intent filter is a way for Android components to declare their capabilities to the Android system.)
Filters play an important role in defining the kind of intent an Android component can receive. A component with no filters can receive only Explicit Intents, whereas components with filters are capable of receiving both Explicit and Implicit Intents. The Intent Resolution uses the following information to map the Intent to the appropriate Android component:
As can be seen, extras and flags have no role here.
Having gone though this Android tutorial, you probably now understand the concepts of Android Intent a little better.
We will discuss more on Intent Filters in our later tutorials. Stay tuned for that. For now, you can join Android Course.
Happy Learning!
edureka.co
Very good site, thank you so much for your time in writing the posts.
This guide helps me a lot in understanding the basics of developing android app! Thanks a lot and stay awesome! ;)
Really good site, thank you so much for your time in writing the posts.
Very good blog, thank you very much for your effort in writing the posts.
Very good blog, thank you so much for your time in writing the posts.
hello there and thank you for your info – I’ve certainly picked up anything new from right here. I did however expertise some technical issues using this website, as I experienced to reload the web site many times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your high quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my email and could look out for much more of your respective intriguing content. Ensure that you update this again very soon..
You get a lot of respect from me for wtrniig these helpful articles.
What an awsmeoe way to explain this-now I know everything!
This will be a fantastic website, would you be interested in doing an interview about how you designed it? If so e-mail me!
Mee too….