Analysis of usage examples of explicit intention and implicit intention in intent of Android learning

This paper illustrates the use of explicit intention and implicit intention in intent of Android learning. Share with you for your reference, as follows:

Intent is mainly to solve the communication between various components of Android applications.

Intent is responsible for describing the action, action related data and additional data of an operation in the application. Android is responsible for finding the corresponding component according to the description of the intent, passing the intent to the calling component and completing the calling of the component.

Therefore, intent acts as a media intermediary here, specifically providing information about components calling each other, so as to realize the decoupling between the caller and the callee.

For example, in a contact maintenance application, when we click a contact on a contact list screen (assuming that the corresponding activity is listactivity), we want to jump out of the contact details screen (assuming that the corresponding activity is detailactivity)

In order to achieve this goal, listActivity needs to construct a Intent, which is used to tell the system that we want to do the "view" action. The action corresponds to the object of the "contact" and then calls startActivity (Intent intent) to transfer the constructed Intent into the system. According to the description in Intent, the system will find the Activity satisfying the Intent requirement in ManiFest, listActivity. The system will call the found activity, that is, detailactivity, and finally pass in an intent. Detailactivity will perform corresponding operations according to the description in this intent.

The classification of intent mainly includes implicit intention and explicit intention. Explicit intention is usually used to start the data between activities in the application, while implicit intention is often used to start some specific actions in the system, such as making a phone call or starting cross application activities.

Generally speaking:

Explicit intent: call intent. Setcomponent() or intent. Setclass() methods to explicitly specify the intent of the component name. Explicit intent specifies which component the intent should be passed to. Implicit intent: an intent that does not explicitly specify a component name is implicit intent. The Android system will find the most appropriate component to handle the implicit intention according to the action, category and data (URI and data type) set in the implicit intention.

The display intention is very common and simple. It is generally used for mutual call conversion between activities in applications. I won't talk more. Here I will introduce the implicit intention:

To sum up, the intention includes: action, category, data, tpye, etc. for example, to put it bluntly, the intention is to start the complete action information of a component, such as hitting people, hitting people is action, people is data content, and type is type. Who to hit? For bad guys, type is the type of bad finger. Only when all this information is available can a complete intention be executed. Of course, there are some information, such as scheme is the prefix of URI type data, such as SMS:, host name, path, etc.

Here I give you an example of calling system SMS, using implicit intention to start system SMS and send information to 10086. The code is as follows:

The above example is something that calls the system. Next, let's see how the user-defined implicit intention is called. First, register in the list file. The code is as follows:

The second activity is customized by us, which is the following code:

How to call custom in the code? In fact, it is the same as calling the system SMS, except that the actions and data in the system SMS are called. The system has been configured for us. We can use it directly, and the customized ones are written by ourselves. The calling method is actually the same as the system. The method is as follows:

Note: intent.setdata (data) and intent.settype (type) note that these two methods will clear each other, which means that if SetData (data) is set first and setType (type) is set later, the setType (type) set later will clear the previous SetData (data) setting and will report an error. Otherwise, if both types and data are set, Then use the setdataandtype (data, type) method.

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>