Intent & Intent-Filters
Intent
- Messaging Object
- Can be used to request an action from another component.
- Facilitate communication between components in several ways.
use-cases
1. Start an activity.
2. Start a service.
3. Deliver a broadcast.
Intent Types
- Explicit intents: Specify the name by component class name. Can be used only to start a component in your own app.
- Implicit intents: Specify the general action to be performed, which allows component from other app to handle it.
If the action is compatible with multiple components, the system displays dialog.
Note: Beginning with Android 5.0 (API level 21), the system throws an exception if you call bindService() with an implicit intent.
Building an Intent
- Intent object carries information that the Android system uses to determine which component to start.
1. Component Name: Name of the component, Optional for implicit intent but critical for explicit intent.
2. Action Name : Specifies the generic action to perform.
3. Data: The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data
4. Category: Additional information about the kind of component that should handle the intent
5. Extras: Key-value pairs that carry additional information required to accomplish the requested action.
6. Flag: flags instruct the Android system how to launch an activity.
Receiving an Implicit Intent
- Declare intent filters for each of your app components with an <intent-filter> element in your manifest file.
- Each intent filter specifies the intent's action, data, and category.
- The system will deliver an implicit intent to your app component only if the intent can pass through one of your intent filters.
Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter.
Android automatically applies the the CATEGORY_DEFAULT category to all implicit intents passed to startActivity() and startActivityForResult().
Using a Pending Intent
- PendingIntent object is a wrapper around an Intent object.
- Grants permission to other application use the contained Intent as it is executed from your own app process.
Use Case: Notification Manager, Alarm Manager and App Widget executes the intent in app process.
Intent Resolution
- TBU
Intent
- Messaging Object
- Can be used to request an action from another component.
- Facilitate communication between components in several ways.
use-cases
1. Start an activity.
2. Start a service.
3. Deliver a broadcast.
Intent Types
- Explicit intents: Specify the name by component class name. Can be used only to start a component in your own app.
- Implicit intents: Specify the general action to be performed, which allows component from other app to handle it.
If the action is compatible with multiple components, the system displays dialog.
Note: Beginning with Android 5.0 (API level 21), the system throws an exception if you call bindService() with an implicit intent.
Building an Intent
- Intent object carries information that the Android system uses to determine which component to start.
1. Component Name: Name of the component, Optional for implicit intent but critical for explicit intent.
2. Action Name : Specifies the generic action to perform.
3. Data: The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data
4. Category: Additional information about the kind of component that should handle the intent
5. Extras: Key-value pairs that carry additional information required to accomplish the requested action.
6. Flag: flags instruct the Android system how to launch an activity.
Receiving an Implicit Intent
- Declare intent filters for each of your app components with an <intent-filter> element in your manifest file.
- Each intent filter specifies the intent's action, data, and category.
- The system will deliver an implicit intent to your app component only if the intent can pass through one of your intent filters.
Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter.
Android automatically applies the the CATEGORY_DEFAULT category to all implicit intents passed to startActivity() and startActivityForResult().
Using a Pending Intent
- PendingIntent object is a wrapper around an Intent object.
- Grants permission to other application use the contained Intent as it is executed from your own app process.
Use Case: Notification Manager, Alarm Manager and App Widget executes the intent in app process.
Intent Resolution
- TBU
0 comments:
Post a Comment