The concept of intent in Android?

I really do not understand how to use and understand the intention. I understand that an activity is one visual interface and one attempt in which the user can participate. I THINK that intent is used to trigger and communicate between different actions. If so, how would you do it? A sample code would be helpful. In an analogy, try comparing intention with something in everyday life. It will help a lot!

+7
android android-intent
source share
8 answers

Intent can be used to trigger actions, provide actions, and some data. An example of using the Intent action to view a web page:

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

If the action is Intent.VIEW_ACTION , and the data row is the Uri of the Google website.

Common tasks and how to do them in Android

I tried, but it's hard to compare with something in everyday life. If I come up with something, I will write it with an answer.

+5
source share

To quote API docs , Intent is basically a passive data structure that contains an abstract description of the actions performed , with two main pieces of information, action and data.

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

The Intent action part is a string or string constant, and the data part is a string representing a URI . In addition to these basic attributes, you can add new attributes through an additional one, which is only a map of key-value pairs.

For more information, see Intents and Intent Filters , Intent , or Intent Play .

I also recommend the Pro Android book, which is detailed in these API details. There is a newer version of Pro Android 2 (did not read it).

If you do a Google Books search for it , you can see excerpts from the book, see Chapter 3, “Using Resources, Content Providers, and Intents” for more information.

+6
source share

I find the ideas quite familiar, especially with some experience integrating applications. Intentions are mostly messages, and Android’s intent / action pair is a message-based architecture using asynchronous messages with one-time and multi-stage guaranteed delivery (I believe), but no guarantees when ordering.

The beauty of message-based interaction is that you disable actions from each other, both in terms of code dependencies (they only need to know about the shared type of intentions and its payload), and in terms of their life cycles (Android is as I understand it, you can terminate and resume either side of a message transaction). This simplifies the management and change of activities, reuse of existing ones and allows the efficient use of resources.

+3
source share

Washing is essentially the way an application declares a need . They work together with IntentFilters, which are mostly advertisements about the possibilities of what another activity or service can do for those who need it.

Prerequisites typically consist of two parts of the type of information and the data component, which is usually the URI (think of a website, GPS data, or contact for dialing).

To use an intent, you must create your intent using this type of information and data, and then send it to another Office, Service, or broadcast receiver, which then usually associates the intent and performs any action that you requested.

The Android API details how to create your own IntentFilters and Receivers. Take a look there for more information.

+1
source share

Suppose that you, your friend, are in two rooms that have no doors and you have no roofs, you want to give him what he needs. So what you do, you put it on the common wall of your rooms so that he can take this thing from the other side. You will probably discard some info in intentions (in some activity) that are global and take this information from the other side (in the next step).

+1
source share

A simple example of the real world according to my understanding, The traditional way of sending messages, i.e. Postal services, you have a letter signed by the sender and the recipient on the cover of the letter (the cover and stamps can be viewed in context - if I'm not mistaken), and the actual letter inside can be considered as data, the total amount of the letter (cover + actual letter data), which the postman carries is intentional, and the postman is the OS :) Hoping this gives some idea.

+1
source share

You correctly said that you need to run and communicate between applications.

http://developer.android.com/guide/topics/fundamentals.html

This has the basics of intent. You need to use .startActivityForResult () rather than startActivity () if you want to get the return value, and have the void onActivityResult (intent intent) method to act as a listener when the value is returned.

The constructor takes 2 parts. The first is an int, which will be a constant in the Intent class to tell the system what you want to do with the data. The second is the URI for passing data between actions. The system then uses them to determine which application should be transferred when you put it in an activity request. As for your analogy, I don’t know, so complicated, it’s actually not very similar. I think the closest thing you get is to pass something on to your boss and tell him that you need someone to do something with this that you cannot.

0
source share

Application Basics Dev defines intentions as "asynchronous messages."

Perhaps in order to better understand their difference from “messages”, they can be compared with WM_COMMAND messages in the Microsoft Windows world, because by definition they should trigger an action (and not just transmit information).

0
source share

All Articles