Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The concept of an Intent in Android?

I don't really understand the use and concept of an Intent. I DO understand that an activity are one visual interface and one endeavour that the user can partake in. I THINK an intent is used to launch and communicate between different activities. If so, then how would you accomplish that? A code sample would be helpful. In analogy form, try to compare an intent to something in everyday life. That would help very much!

like image 828
Mohit Deshpande Avatar asked Apr 07 '10 01:04

Mohit Deshpande


People also ask

What an Intent is in Android?

Android Intent Tutorial. Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke activity, broadcast receivers etc. The dictionary meaning of intent is intention or purpose.

What is Intent explain its object?

An Intent object is a bundle of information which is used by the component that receives the intent as well as information used by the Android system. An Intent object can contain the following components based on what it is communicating or going to perform −


3 Answers

To quote the API docs, an Intent is basically a passive data structure holding an abstract description of an action to be performed, with two primary pieces of information, action and data.

At the most basic level, an Intent can be seen as an action that you can tell Android to invoke - and what happens depends on what is registered for that action.

The action part of an Intent is a string or string constant, and the data portion is a string representing a URI. In addition to these main attributes, you can add new attributes via an extra, which is just a map of key-value pairs.

For more info, refer to Intents and Intent Filters, the Intent class, or Playing with Intents.

I also recommend the book Pro Android, which goes into these API details at length. There is a newer version called Pro Android 2 (haven't read it).

If you search Google Books for it, you can see extracts of the book, look at Chapter 3, "Using Resources, Content Providers, and Intents" for more info.

like image 121
JRL Avatar answered Sep 23 '22 02:09

JRL


An Intent can be used to launch activities, by supplying an action and some data. An example of using an Intent action to view a web-page:

Intent myIntent = new Intent(Intent.VIEW_ACTION,
                  Uri.parse("http://www.google.com"));

Where the action is Intent.VIEW_ACTION and the data string is an Uri of Google's website.

Common Tasks and How To Do Them in Android

I have tried, but its tough to compare an Intent with something in everyday life. If I come up with something, I'll jot it down with my answer.

like image 32
Anthony Forloney Avatar answered Sep 24 '22 02:09

Anthony Forloney


I find intents quite familiar, especially with some experience in application integration. Intents are basically messages, and the Android intent/activity pair is a message based architecture using asynchronous messages with both single and multi-casting, guaranteed delivery (I believe), but no guarantees on ordering.

The beauty of message based interaction is that you decouple activities from each other, both in terms of code dependencies (they need only know about a shared intent type and its payload), and in terms of their lifecycles (Android is as I understand it free to stop and resume either party in the message transaction). This makes it easier to maintain and modify activities, to reuse existing ones, and permits efficient use of resources.

like image 43
Pontus Gagge Avatar answered Sep 24 '22 02:09

Pontus Gagge