Unit - 1 Intent and It's types



Lesson Plan: Unit - 01
Subject: P15A2AAD - Android Application Development
Topic of Study: Intent and It's Types
Grade/Level: Master of Computer Applications
Objective: To understand the parameters of Intent & it's types with demonstration
Time Allotment: 55 Minutes
  • Intent
    • An intent is an abstract description of an operation to be performed.
    • An Intent provides a facility for performing late run time binding between the code in different applications. 
    • Its most significant use is in the launching of activities, where it can be thought of as the glue between activities.
    • Intents are the standard messaging mechanism in Android that expresses the user’s intention to perform some work. 
    • They allow you to interact with other components defined by you or by the Android operating system.
    • Example:
      • Broadcast a message
      • Start the camera
      • Start a service
      • Launch an activity
      • Display a web page or a list of contacts
      • Dial a phone number or answer a phone call

    • An Intent object is a bundle of information which is used by the component that receives the intent.
    • They are used in both ways
      • 1) by you to call a component
      • 2)by the system to notify you of some event.
    • Where Intent can be used?
      • Context.startActivity() 
        • The Intent object is passed to this method to launch a new activity or get an existing activity to do something new.
      • Context.startService() 
        • The Intent object is passed to this method to initiate a service or deliver new instructions to an ongoing service.
      • Context.sendBroadcast() 
        • The Intent object is passed to this method to deliver the message to all interested broadcast receivers.
    • The logical workflow of creating an intent is usually as follows:
      • a. Create the Intent
      • b. Add Intent options-> Ex. what type of intent we are sending to the OS or any attributes associated with that intent, such as a text string or something being passed along with the intent.
      • c. RUN the Intent
    • Intent Structure
    • The primary pieces of information in an intent are:
      • action
        • It is mandatory part of the Intent object. 
        • The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
        • Exa.
          • ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1".
          • ACTION_EDIT content://contacts/people/1 -- Edit information about the person whose identifier is "1".
          • ACTION_VIEW tel:123 -- Display the phone dialer with the given number filled in
      • data
        • It is adds a data specification to an intent filter. 
        • The data to operate on, such as a person record in the contacts database, expressed as a Uri.
    • There are a number of secondary attributes that you can also include with an intent:
      • category
        • It is an optional part of Intent object. 
        • 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. 
      • component
        • It is name of optional field representing either Activity, Service or Broadcast Receiver. 
        • Specifies an explicit name of a component class to use for the intent. 
        • Normally this is determined by looking at the other information in the intent (the action, data/type, and categories) and matching that with a component that can handle it. 
      • extras
        • It is in key-value pairs for additional information. 
        • This is a Bundle of any additional information. 
        • This can be used to provide extended information to the component. 
        • For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.
    • Intent Types or Intent Resolution
      • There are two primary forms of intents you will use.
        • Explicit Intents
          • Explicit intent going to be connected internal world of application.
          • Exa. To connect one activity to another activity.

          • It 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.

        • Implicit Intents
          • These intents do not name a target and the field for the component name is left blank. 
          • Implicit intents are often used to activate components in other applications.

          • have not specified a component; 
          • instead, they must include enough information for the system to determine which of the available components is best to run for that intent.
          • Exa.

        • Pending Intents
          • ?
        • Sticky Intents
          • ?

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form