Three core components in Android applications: Activities,services and broadcast receivers are activated by messages called "Intent." One feature of Android applications is "low coupling", where individual activities,services and broadcast receivers are quite independent and can be viewed as "mini apps", and intent are the glue for these "mini applications", Intent can be used not only for interaction between activities,services and broadcast receivers between the same application, but also for application between different activities, The interaction between services and broadcast receivers.
The intent itself is a data carrier that describes the actions you want to perform and the data and other attributes that are used for this operation. With an easy to understand concept, when visiting a website, we need to provide the URL of the website, sometimes also need to pass the URL parameter, in the Android world, Intent function is similar to the url,android operating system according to Intent to trigger the activitives, Services or broadcast receivers.
Three core components of Android applications: Activities,services and broadcast receivers are triggered by intent, when they trigger different mechanisms and do not overlap, That is to say, the intent that sends the activity does not activate the service or broadcast receivers, and the receivers to broadcast intent does not trigger active and service.
The activity is invoked by means of context.startactivity () and Activity.startactivityforresult (). Using a function call as a reference startactivity () is equivalent to calling a function that has no return value, the activity of the Startactivityforresult () call has a return value, and the result can be returned by Activity.setresult ().
Context.startservice () is used to initialize Service,context.bindservice () that can be used to establish a connection to the target service, and if the service is not running, the service is started.
Broadcast receiver are triggered by context.sendbroadcast (), Context.sendorderedbroadcast (), and Context.sendstickybroadcast (). Most of the broadcast messages come from the Android operating system, such as battery status, incoming calls, short messages, and so on.
Unlike URLs, URLs and Web sites are typically one by one corresponding, and a intent can be used to trigger a specified Activity,service or broadcast Receiver, or to trigger multiple intent that meet the activities condition. Services or broadcast receivers.
Here's how the Android OS finds Activity,service or broadcast Receiver that meet the trigger conditions based on intent. The concept of using the SQL database can be better understood.
SELECT (activitives| services| Broadcast receivers) as Target
From (List in Androidmanifest.xml)
WHERE Intent Meet Target ' s (Intent Filter)
The meaning is to look up intent from the Activities,services and broadcast receiver lists defined in Androidmanifest.xml to match the activities,services condition. or broadcast receivers. All live activated Activity,service and broadcast receiver must be defined in Androidmanifest.xml, otherwise the Android OS cannot query the target, which is equivalent to no records in the database. Even if you define the Activity,service or broadcast Receiver in your code.
Intent
The intent itself is a data carrier that describes the actions you want to perform and the data and other attributes that are used for this operation. It mainly contains the following information:
Component Name: The name of the component that can handle the intent, and the component name refers to the full name of the package and class that defines Activity,service. For example, the class name is com.pstreets.gisengine.AndroidGISEngineTutorial and the package name is Com.pstreets.gisengine. The component name is called an optional, and if specified, it means explicitly specifying the activity,service that should be used to ring the intent.
Action: Lists the name of the action that needs to be performed. or give the event name that occurred when broadcast intents.
| Constant |
Target component |
Action |
| Action_call |
Activity |
Start calling. |
| Action_edit |
Activity |
Displays the Edit dialog box. |
| Action_main |
Activity |
As a starting activity for a task (application), it is necessary to set the Action_main intent-filter attribute in Androidmanifest.xml for applications that can be applied from the Android application list. |
| Action_sync |
Activity |
Synchronize the data. |
| Action_battery_low |
Broadcast receiver |
Low battery alarm. |
| Action_headset_plug |
Broadcast receiver |
Headphones plugged in or unplugged. |
| action_screen_on |
Broadcast receiver |
The screen is turned on or off. |
| Action_timezone_changed |
Broadcast receiver |
Time zone changes. |
Data: Defines a URL with no data and the MIME type of the data. Different ACTION can handle the same type of data, such as Action_call, which is processed in the format of Tel:uri,uri as a phone number.
Category: Defines additional information that can respond to intent, and a intent can specify multiple Category types. Like action, Android has pre-defined some category types:
| Constant |
Meaning |
| Category_browsable |
Indicates that the target activity can display the specified connection using a browser security, such as a picture or an email message. |
| Category_gadget |
Indicates that the activity can be embedded as a gadget into other activity that can be placed gadget. |
| Category_home |
Indicates that the activity is home screen, and you can set this property to replace the Android home screen with its own. |
| Category_launcher |
The activity can be displayed in the Android program manager. The main activity of the general application defines the attribute in Androidmanifest.xml. |