Android Insights - 1 [Intents]


Published on

- Introduction to intents & intent filters.
- How intents and intent filters work.

Presentation by:
Sharafat Ibn Mollah Mosharraf

Published in: Technology, Art & Photos
1 Comment
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Android Insights - 1 [Intents]

  1. 1. Android Insights - 1 Intents
  2. 2. Topics to be Covered• Basic Components of Android• Intents & Intent Filters• Intent Resolution2/8/2012 Android Insights - 1 2/10
  3. 3. Basic Components of Android• Activity – provides a screen with which users can interact in order to do something• Service – performs long-running operations in the background and does not provide a user interface• Content Provider – manages access to a structured set of data• Intent – an abstract description of an operation to be performed2/8/2012 Android Insights - 1 3/10
  4. 4. Motivation Towards Intents• We want all the activities, services, broadcast receivers etc. to be loosely-coupled.• Message Passing is the way to go.• Intents are those messages which are used to communicate among the components.Remember? “An intent is an abstract descriptionof an operation to be performed.”2/8/2012 Android Insights - 1 4/10
  5. 5. Primary Structure of an Intent• Action – The general action to be performed• Data – The data to operate on, expressed as a URI.Example of an action-data pair:ACTION_VIEW content://contacts/people/1Display information about the person whose identifieris "1".2/8/2012 Android Insights - 1 5/10
  6. 6. How Intents Work• Given an arbitrary intent we need to know what to do with it.• This is handled by the process of Intent resolution, which maps an Intent to an Activity, BroadcastReceiver, or Service (or sometimes two or more activities/receivers) that can handle it.• The intent resolution mechanism basically revolves around matching an Intent against all of the <intent- filter> descriptions in the installed application packages.• There is a manifest file in the next slide where activities are marked with the intents they can operate on.2/8/2012 Android Insights - 1 6/10
  7. 7. How Intents Work... What are those category and data elements in intent filters??2/8/2012 Android Insights - 1 7/10
  8. 8. The Other Parts of Intent• Category – Gives additional information about the action to execute. – For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application.• Type – Specifies an explicit type (a MIME type) of the intent data. – Normally the type is inferred from the data itself. By setting this attribute, you disable that evaluation and force an explicit type. – For example, setting type to image/jpeg means the activity can handle only jpeg files and not other image files such as png, gif etc.• Extras – A Bundle of any additional information. – Can be used to provide extended information to the component. – For example, an ACTION_HEADSET_PLUG has a "state" extra indicating whether the headset is now plugged in or unplugged, as well as a "name" extra for the type of headset.• Flags – Flags of various sorts. – For example, in the case of FLAG_ACTIVITY_NO_ANIMATION, if set in an Intent passed to Context.startActivity(), this flag will prevent the system from applying an activity transition animation to go to the next activity state.2/8/2012 Android Insights - 1 8/10
  9. 9. Explicit IntentsHey, the Intent-Resolution mechanism of Android is cool, butI just need to start a new activity – that’s all. All those fuzzaren’t worth of merely starting an activity, I guess???• You’re right.• There is a last part in an intent – Component.• An intent can have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run.• Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application.• Intents having components set are called Explicit Intents in contrast to their counterparts Implicit Intents.2/8/2012 Android Insights - 1 9/10
  10. 10. References• Intent Structure and Intent Resolution Mechanism: tents/intents-filters.html• Standard actions, categories, flags and extra data: oid/content/Intent.html2/8/2012 Android Insights - 1 10/10