Summary of intent usage in Android Development

This article illustrates the use of intent in Android development. Share with you for your reference, as follows:

In Android mobile phone software development, intent, as a very important object in mobile phone software development, needs our attention. In fact, intent is also a symbolic object reflecting the unique characteristics of Android development.

When an activity wants to start another activity, perhaps a familiar pattern is to call a new function to directly create an object with a window feature class, or directly call a startup function to start it. This approach is concise and clear, but it violates the concept of Android development. Android uses intent to "encapsulate" the program's "calling intention". No matter what component the program wants to start, whether it starts an activity, a service, or a broadcast receiver, Android uniformly uses intent objects to encapsulate this "starting intention".

In addition, using intent also has advantages. Sometimes, applications just want to start components or applications with certain characteristics, but do not want to have hard code coupling with such programs; In addition, sometimes an application only knows some characteristics of the thing to be started, but does not know what the program to be started specifically refers to (for example, a program wants to start an application for sending text messages, and at this time, there are multiple messaging software in the system, so we can't know what software to open), At this point, the program should send an intention to start the SMS application, rather than specify what software to open. Of course, more generally, intent can also specify which application to open, and has a hard coupling relationship with some programs.

Intent is also an important medium for communication between application components. The two activities encapsulate the data to be exchanged into a bundle object, and then use intent to carry the bundle object, so as to realize the data exchange between the two activities.

Intent has the following attributes: component, action, category, data, type, extra and flag. The component attribute is used to specify the target component to be started, and the extra attribute is used to carry the data to be exchanged.

The intent object is described in detail below:

1. Component attribute of intent @ h_ 404_ 18@

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
分享
二维码
< <上一篇
下一篇>>