Intent in Android and Sharing
Intents indicate the intention of your app, it's a sort of description of something that the app wants an activity to perform. Intents are description that the system uses to locate activities on behalf of applications.
They come in 2 flavours:
They come in 2 flavours:
- Explicit
- Implicit
# Explicit
is used to launch an specific activity using the name of the target activity class and they are typically only used to launch other activities within your application. The navigation component does this for you when you navigate to other activities in the navigation graph.
# Implicit
provide an abstract description of the operation to be performed and they most often are used to launch activities that are exposed by other applications.
Example:
If you want to locate the grocery store :
Explicit intent used to locate this grocery store need the specific local convenience store.
Implicit intent would include the grocery store within a 5 mile radius that sold organic things. During this case the system might have no apps to handle implicit intent like there might be no grocery store. Or it can have multiple apps. So the android will pop up with a chooser to handle such intent.
# Intent Actions
are used in intent to describe the type of thing that is to be done. Common actins are defined in the intent class such as : Intent.ACTION_VIEW, Intent.ACTION_DIAL, Intent.ACTION_EDIT
#Intent Category
implicit intents have a category and datatype, to further describe the operation, categories aren't always used, but are used to further disambiguate the action.
It is used in the main entry point action like : CATEGORY_APP_MUSIC, CATEOGRY_APP_MAPS, CATEGORY_APP_EMAIL, CATEGORY_APP_GALLERY,...
# Intent Data Type (MIME Data Type)
Allows activities to support specific data types.
implicit intent can include data type such as text or JPEG image, which allows applications to be chosen based on the data type they can accept.
All activities must be registered in android Manifest.xml to be launched.
Activities that can be launched explicitly can be just declared with <activity> tag
While implicitly launched activity require an intent filter.
#Intent Filter
is used to expose that your activity can respond to an implicit intent with certain action, category and/or type.
Comments
Post a Comment