-1

I am new to android and am currently reading a book called 'Professional.Android.2.Application.Development'. I have seen some of the code given to me to start an application development and I have noticed that most of the java code consists of intents.

I want to know why we are using intents and not events or services.

All I know about intents are that they are an abstract description of an operation to be performed.

I also want to know the importance of intents in android.

Can anyone please explain it to me as I am new and a little bit confused.

SemperFi
  • 2,358
  • 6
  • 31
  • 51
  • There is a nice explanation of `Intent` [here](http://stackoverflow.com/questions/6578051/what-is-intent-in-android) – Renjith Apr 24 '13 at 04:09

1 Answers1

5

What is a Intent ?

Intent is basically a message that is passed between components (such as Activities, Services, Broadcast Receivers, and Content Providers). So, it is almost equivalent to parameters passed to API calls. The fundamental differences between API calls and intents’ way of invoking components are:

  • API calls are synchronous while intent-based invocations are asynchronous.
  • API calls are compile time binding while intent-based calls are run-time binding.

Of course, Intents can be made to work exactly like API calls by using what are called explicit intents, which will be explained later. But more often than not, implicit intents are the way to go and that is what is explained here.

One component that wants to invoke another has to only express its’ intent to do a job. And any other component that exists and has claimed that it can do such a job through intent-filters, is invoked by the android platform to accomplish the job. This means, both the components are not aware of each other’s existence and can still work together to give the desired result for the end-user.

This invisible connection between components is achieved through the combination of intents, intent-filters and the android platform.

This leads to huge possibilities like:

  • Mix and match or rather plug and play of components at runtime.
  • Replacing the inbuilt android applications with custom developed applications.
  • Component level reuse within and across applications.
  • Service orientation to the most granular level, if I may say.
  • Here is additional description about intent, almost formal.

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed. The primary pieces of information in an intent are:

  • action The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
  • data The data to operate on, such as a person record in the contacts database, expressed as a Uri.

On this data structure is that the android is implemented as you read the following documentation is very helpful:

SBotirov
  • 13,872
  • 7
  • 59
  • 81