Android Intent

In our Android instructional exercise covering fresher interview questions, we had clarified the use of Intent in Facebook with the accompanying case:

Assume you are on the news encourage screen (which is one Activity), and need to see a pic posted by our companion. When you tap on the photograph, the expectation connected with the snap occasion of photograph is let go which imparts the message, and the Photo page opens (which is another Activity).

Android Tutorial: Intent ComponentSo, we expect that you comprehend somewhat about Android Intent. This Android instructional exercise would talk about a couple of more profound ideas connected with the point.

Consider expectation a message to impart an activity. It is a portrayal of what you need done, case: VIEW VIDEO, PLAY GAME and so on.

They are charges which when called would go about as communicators between the three center segments of Android, i.e. Exercises, Services and Broadcast Receivers.

While you are communicating with one movement, you might need to change to another; this is finished by characterizing a legitimate Intent for the activity. Here one Activity utilizes Intent to ask for the dispatch of another Activity. Consequently, it is apparent that utilizing aims, one Android segment can ask for activity from alternate segments of Android.

To improve this, let us at the end of the day take a comparable case of the Facebook application.

The case beneath accept that you are on the Photo Gallery Activity, and need to see a particular photograph (which would open in its own action). This is the manner by which the Intent connected with the snap photograph occasion is let go:

Android Tutorials for tenderfoots: Intent part of Android

Once in a while, one can characterize Intent to inform the Android framework about the event of an occasion. This is unequivocally what occurs if there should be an occurrence of Broadcast Receivers (for example, expectation is characterized to convey battery low notice to the client).

We should take another case of the Domino’s Pizza application. Give us a chance to assume you are survey the Menu Screen (Activity) of the application, and need to choose a pizza. When you select the Mexican Wave pizza, and tap on Customize catch, another screen (action) flies up, where you can additionally determine the measure of the pizza, kind of outside you need and so forth. Here, the Click Action (Select Pizza Intent) on the Menu imparted the message to open the new popup window (new movement).

Android Tutorials for learners: Intent Example utilizing Domino’s Pizza application

Basic; right! Give us a chance to get a little into the subtle elements in the following part of the Android instructional exercise:

2. Expectation Object

On the off chance that you wish to make a supper date with your companion, and are passing on the data through a delivery person, you should give the courier subtle elements like the name of your companion and the specifics of the coveted meeting (time, put, and so forth.). Not having given the specifics of the meeting to the delivery person, you can’t simply expect that they would make sense of what to do. You may compose this data on a bit of paper for the dispatcher’s reference.

So also, as expectation is a message, the total data that it needs to pass on must be put away some place, right! Purpose Object deals with that.

2.1 What data does Intent Object contain?

Goal Object contains all the data that the “Purpose” intends to pass on:

All the data required by the part getting the Intent (for example, the move to make on accepting the Intent). (In the above illustration, this would be the data implied for your companion’s information, similar to the area of the meeting, time of the meeting and so forth.)

The data required by the Android framework (for example, the portrayal of the Component classification the Intent is coordinated at) is contained in the Intent Object. (In the above case, the data required by the emissary itself would frame a piece of this, similar to the name of the companion, his address and so forth.)

The accompanying data frames a piece of Intent Object:

Part name: This data is discretionary. In the event that the segment name is set, the Android framework straightforwardly maps the purpose to the objective part. In different cases, the framework uses other data to find the appropriate target. The segment name is set by setComponent (), setClass () or setClassName (), and is perused by getComponent ().

Activity: This bit of data names the activity an Android segment ought to go up against accepting the Intent, or the move that has officially made place, and is being advised to the framework. The Android framework characterizes various Action Constants. We have recorded two in this Android instructional exercise:

Android Tutorials: Intent Object Action

Information: Contains the Uniform Resource Identifier (URI) of the information. There are diverse sorts of information determinations for various activities. For example, if the activity characterized were ACTION_CALL, the information field would contain a number to call (tel: URI). For accurately coordinating Intent to a reasonable segment, characterizing the information sort (notwithstanding the URI) makes a difference. For example, a segment to show picture ought to be called to show picture just, not to play a sound record.

Class: This characterizes the classification of the segment that would handle the Intent.

Additional items: This is the extra data that requirements conveyed to the segment taking care of the goal.

Banners: Many banners can be a part of the data contained in Intent Object. For example, banners can teach the Android framework to dispatch a movement in a particular way (you can indicate that the new action be propelled in another window of the program.)

3. Purpose Types

Diving further, Intents can be Explicit or Implicit.

3.1 Explicit Intent:

An Explicit Intent is precisely what it implies truly: an “unequivocal aim” to play out an activity. Basically, for this situation, we characterize unequivocally the Android part (Activity, Service or Broadcast Receiver) that requirements calling.

Test Code 1: Explicit Intent specimen code Android Tutorials: Explicit Intent example code Android Tutorials for tenderfoots: Explicit Intent Example

3.2 Implicit Intent

Here we don’t particularly characterize the segment that should be called. Be that as it may, the Intent contains enough data to guide the framework to get the right one.

Test Code 2: Implicit Intent specimen code Android instructional exercises for fledglings: Implicit Intent example code

Above certain expectation advises the Android System to see the Web Page gave in the URI.

Understood Intent Example: Basic Android instructional exercises

4. Plan Resolution

In light of the subjective way of Implicit Intents, the framework utilizes a procedure called Intent Resolution to guide them effectively. The framework does this by coordinating the Intent depiction with the default portrayals in the framework.

Expectation Object, characterized prior becomes possibly the most important factor here. The Intent Resolution looks at the substance of Intent Object against the Intent Filters. (Expectation Filters are connected with the distinctive Android parts, and can get Intent. Plan channel is a path for Android segments to proclaim their capacities to the Android framework.)

Channels assume a vital part in characterizing the sort of aim an Android segment can get. A segment without any channels can get just Explicit Intents, though parts with channels are fit for accepting both Explicit and Implicit Intents. The Intent Resolution utilizes the accompanying data to delineate Intent to the fitting Android part:

The activity

The sort (information sort and URI)

The class

As can be seen, additional items and banners have no part here.

Having gone however this Android instructional exercise, you likely now comprehend the ideas of Android Intent somewhat better.

Have an uncertainty with any subject examined in this Android instructional exercise? Ask Us!

We will examine more on Intent Filters in our later instructional exercises. Stay tuned for that. Until further notice, you can join Android Course.

Glad Learning!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.