SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
Ch5. Intent, Broadcast
Receivers, Adapters, and
      the internet
          Browny
        16, May, 2011
Outline


• Introducing Intents
• Introducing Adapters
• Using Internet Resources
• Introducing Dialogs
Interaction

• Mobile applications on most platforms
  are isolated from each other, and have
  strict limitations applied to their
  interaction with hardware and native
  components
• Android applications use Intents,
  Broadcast Receivers, Adapters, Content
  Providers, and the Internet to interact
  through those boundaries
Intents

• A message-passing mechanism (within
  and between applications)
• Intents can be used to:
 ‣   Declare	
  your	
  inten.on	
  that	
  an	
  Ac.vity	
  or	
  Service	
  
     be	
  started	
  to	
  perform	
  an	
  ac.on,	
  usually	
  with	
  (or	
  
     on)	
  a	
  par.cular	
  piece	
  of	
  data
 ‣   Broadcast	
  that	
  an	
  event	
  (or	
  ac.on)	
  has	
  occurred
 ‣   Explicitly	
  start	
  a	
  par.cular	
  Service	
  or	
  Ac.vity
Using Intents to Launch Activities

• To open an Activity, call startActivity,
  passing in an Intent
  ‣   Explicitly	
  (Explicitly	
  specify	
  the	
  Ac.vity	
  class	
  to	
  
      open)
  ‣   Implicitly	
  (Include	
  an	
  ac.on	
  that	
  an	
  Ac.vity	
  
      must	
  perform)

• Intent resolution: Decide what activity
  is chosen to take that action (for
  implicitly)
Explicitly Starting New Activities
                (1/2)



1. Create a new Intent
2. Specifying the current application
   Context and Activity class to launch
3. Pass this Intent in to startActivity
Explicitly Starting New Activities
                (2/2)

• After startActivity is called, the new
  Activity will be created and become
  visible and active, moving to the top of
  the Activity stack
• Calling finish on the new Activity, or
  pressing the hardware back button, will
  close it and remove it from the stack
Implicit Intents (1/3)

• A mechanism that lets anonymous
  application components service action
  requests (without knowing exactly which
  application you’re borrowing functionality
  from)


• Android will at run time resolve it into
  the Activity class best suited to
  performing the required action on the
  type of data specified
Implicit Intents (2/3)

• Example: Let users make calls from
  your application
 ‣   Implement	
  a	
  new	
  dialer	
  ?
 ‣   Use	
  an	
  implicit	
  Intent	
  that	
  requests	
  the	
  ac.on	
  
     (dialing)	
  be	
  performed	
  on	
  a	
  phone	
  number
Implicit Intents(3/3)

• Various native applications provide
  Activities to handle actions performed
  on specific data
• Third-party applications, including
  your own, can be registered
 ‣   To	
  support	
  new	
  ac.ons
 ‣   To	
  provide	
  an	
  alterna.ve	
  provider	
  of	
  na.ve	
  
     ac.ons
Returning Results from Activities

• startActivity will not provide any
  feedback
• You can start an Activity as a sub-
  Activity that’s inherently connected to
  its parent
  ‣   A	
  sub-­‐Ac.vity	
  triggers	
  an	
  event	
  handler	
  within	
  
      its	
  parent	
  Ac.vity	
  when	
  it	
  closes	
  
  ‣               :	
  One	
  Ac.vity	
  is	
  providing	
  data	
  input	
  
      for	
  another
Sub-Activities


• Just Activities opened in a different way
• Must be registered in the application
  manifest
• Any manifest-registered Activity can be
  opened as a sub-Activity (system or
  third-party)
Launching Sub-Activities (1/3)


• startActivityForResult
  ‣   Also	
  pass	
  in	
  a	
  request	
  code	
  (will	
  later	
  be	
  used	
  to	
  
      uniquely	
  iden.fy	
  the	
  sub-­‐Ac.vity)
Launching Sub-Activities (2/3)

• Sub-Activities can be started implicitly
  or explicitly
• When your sub-Activity is ready to
  return, call setResult before finish to
  return a result to the calling Activity
Launching Sub-Activities(3/3)

• The setResult method takes 2
  parameters: the result code and the
  result itself (represented as an Intent)


• Example: A sub-Activity’s onCreate
  method, and shows how an OK and
  Cancel button might return different
  results to the calling Activity (next
  page)
If the Activity is closed by the user pressing the hardware back key, or finish is called
without a prior call to setResult, the result code will be set to RESULT_CANCELED and the
result Intent set to null
Handling Sub-Activity Results

• When a sub-Activity closes, the
  onActivityResult event handler is fired
  within the calling Activity (override this
  method)
• The onActivityResult handler receives a
  number of parameters
 ‣   Request	
  code
 ‣   Result	
  code
 ‣   Data
Native Android Actions

• Native Android applications also use
  Intents to launch Activities and sub-
  Activities
• When creating implicit Intents you can
  use these actions (called Activity
  Intents) to start Activities and sub-
  Activities within your own applications
 ‣   ACTION_ANSWER,	
  ACTION_CALL,	
  ACTION_EDIT,	
  
     ACTION_PICK,	
  etc...
Using Intent Filters to Service
          Implicit Intents

• How does Android know which
  application (and component) can
  service the request ?


• Intent Filters are used to register
  Activities, Services, and Broadcast
  Receivers as being capable of
  performing an action on a particular
  kind of data
Registering an Activity as an Intent
          Receiver(1/2)

• Add an <intent-filter> tag to the
  component’s manifest node using the
  following tags (and associated
  attributes) within the Intent Filter
  node
Registering an Activity as an Intent
          Receiver(2/2)
• action
 ‣   Each	
  Intent	
  Filter	
  must	
  have	
  one	
  (and	
  only	
  one)	
  ac.on	
  
     tag.	
  Ac.ons	
  should	
  be	
  unique	
  strings	
  that	
  are	
  self-­‐
     describing

• category
 ‣   Specify	
  under	
  which	
  circumstances	
  the	
  ac.on	
  should	
  
     be	
  serviced	
  (ALTERNATIVE,	
  SELECTIVE_ALTERNATIVE,	
  
     BROWSABLE,	
  etc...)

• data
 ‣   Specify	
  which	
  data	
  types	
  your	
  component	
  can	
  act	
  on
How Android Resolves Intent Filters

1. Listing all the Intent Filters available
   from the installed packages
2. Matching the action or category
   associated with the Intent
3. Matching data
4. If more than one component is resolved
   from this process all the matching
   possibilities are offered to the user
Using the Launch Intent Within an
             Activity
•   When an application component is started
    through an implicit Intent, it needs to find the
    action to be performed and the data to be
    performed on
•   Use the getData and getAction methods to find
    the data and action associated with the Intent
Passing on Responsibility

• Use the startNextMatchingActivity
  method to pass responsibility for
  action handling to the next best
  matching application component
Using Intent Filters for Plug-Ins and
           Extensibility


• A plug-in model for your Activities
  that lets them take advantage of
  future functionality


• Using Intent Filters to populate
  menus dynamically at run time
Supplying Anonymous Actions to
        Applications (1/2)

• Make your Activity’s actions available
  anonymously for existing applications
 ‣   Publish	
  them	
  using	
  intent-­‐filter	
  tags	
  within	
  their	
  
     manifest	
  nodes
 ‣   The	
  category	
  tag	
  must	
  be	
  either	
  ALTERNATIVE	
  
     or	
  SELECTED_ALTERNATIVE	
  or	
  both
 ‣   The	
  text	
  used	
  for	
  the	
  Menu	
  Items	
  is	
  specified	
  by	
  
     the	
  android:label	
  aVribute
Supplying Anonymous Actions to
        Applications(2/2)
Incorporating Anonymous Actions in
       Your Activity’s Menu




         ...
Introducing Linkify

• Linkify is a helper class
 ‣   Automagically	
  creates	
  hyperlinks	
  within	
  Text	
  
     View	
  (and	
  Text	
  View-­‐derived)	
  classes	
  through	
  
     RegEx	
  paVern	
  matching
 ‣   Text	
  that	
  matches	
  a	
  specified	
  RegEx	
  paVern	
  will	
  
     be	
  converted	
  into	
  a	
  clickable	
  hyperlink
 ‣   Implicitly	
  fires	
  startAc/vity(new	
  Intent
     (Intent.ACTION_VIEW,	
  uri)),	
  using	
  the	
  matched	
  
     text	
  as	
  the	
  target	
  URI
The Native Linkify Link Types
 • How to linkify a Text View to display
   web and e-mail addresses as
   hyperlinks


• You can also linkify Views from within a
  layout resource using the android:autoLink
  attribute
Using Intents to Broadcast Events

• Intents are capable of sending structured
  messages across process boundaries
• By broadcasting an event using an Intent
  you let yourself and third-party developers
  react to events without having to modify
  your original application
• Android uses broadcast Intents to
  broadcast system events like battery-
  charging levels, network connections, and
  incoming calls
Broadcasting Events with Intents

• Construct the Intent you want to broadcast
  and use the sendBroadcast method to send it
• The Intent action string is used to identify
  the event being broadcast, so it should be a
  unique string that identifies the event
Broadcast Receivers(1/2)

• For a Broadcast Receiver, it needs to
  be registered, either in code or within
  the application manifest
Broadcast Receivers(2/2)

•   Applications with Broadcast Receivers registered
    in the manifest don’t have to be running when the
    Intent is broadcast for the receivers to execute.
    They will be started automatically when a matching
    Intent is broadcast


•   The five-second execution limit ensures that major
    processing cannot, and should not, be done within
    the Broadcast Receiver itself (update content,
    launch Services, update Activity UI, etc...)
Registering Broadcast Receivers in
    Your Application Manifest



Even when the application has been killed or hasn’t been started




Only when the application component it is registered within is running
Broadcasting Sticky and Ordered
            Intents


• Problem: When broadcasting an Intent
  using sendBroadcast, your Intent will
  be received by all registered
  Broadcast Receivers, but you cannot
  control the order and they cannot
  propagate results
Native Android Broadcast Actions

• You can use these messages to add
  functionality to your own projects based
  on system events such as time-zone
  changes, data-connection status, incoming
  SMS messages, or phone calls


• ACTION_CAMERA_BUTTON,
  ACTION_SCREEN_OFF,
  ACTION_TIMEZONE_CHANGED,
  etc...
Pending Intents

• The Pending Intent class provides a
  mechanism for creating Intents that
  can be fired by another application at
  a later time


• Commonly used to package an Intent
  that will be fired in response to a
  future event
Introducing Adapters

• Adapters are bridging classes that bind
  data to Views (such as List Views) used
  in the user interface
• Views that support Adapter binding
  must extend the AdapterView abstract
  class
• You can create your own AdapterView
  derived controls and to create new
  Adapter classes to bind them
Some Native Adapters


• ArrayAdapter
 ‣   Array	
  Adapter	
  uses	
  the	
  toString	
  value	
  of	
  each	
  
     object	
  in	
  the	
  array	
  to	
  create	
  and	
  populate	
  Text	
  
     Views

• SimpleCursorAdapter
 ‣   You	
  specify	
  an	
  XML	
  layout	
  defini.on,	
  and	
  then	
  
     bind	
  each	
  column	
  to	
  a	
  View	
  within	
  that	
  layout
Customizing the Array Adapter


• Customize the layout used to
  represent each View
• Extend ArrayAdapter with a type-
  specific variation, overriding the
  getView method to assign object
  properties to layout Views
Using Adapters for Data Binding

• Apply an Adapter to an AdapterView
  derived class: Call the View’s
  setAdapter, passing in an Adapter
  instance
Using Internet Resources

• Benefits (client native applications rather
  than entirely web-based solutions)
 ‣   Bandwidth:	
  By	
  crea.ng	
  a	
  na.ve	
  applica.on	
  you	
  
     can	
  limit	
  the	
  bandwidth	
  requirements	
  to	
  updated	
  
     data	
  only
 ‣   Caching:	
  A	
  na.ve	
  applica.on	
  can	
  cache	
  data	
  to	
  
     provide	
  as	
  much	
  func.onality	
  as	
  possible	
  without	
  a	
  
     live	
  connec.on
 ‣   Na4ve	
  features:	
  combine	
  the	
  data	
  available	
  online	
  
     with	
  the	
  hardware	
  features	
  available	
  on	
  the	
  device
Connecting to an Internet Resource

• Add an INTERNET uses-permission node to
      your application manifest
  ‣     <uses-­‐permission	
  android:name="android.permission.	
  INTERNET"	
  />
Using Internet Resources

• 2 extreme
 ‣   Include	
  a	
  WebKit-­‐based	
  browser	
  View	
  within	
  an	
  
     Ac.vity
 ‣   Use	
  client-­‐side	
  APIs	
  to	
  interact	
  directly	
  with	
  
     server	
  processes

• Between
 ‣   Process	
  remote	
  XML	
  feeds	
  to	
  extract	
  and	
  
     process	
  data	
  using	
  a	
  Java-­‐based	
  XML	
  parser	
  
     such	
  as	
  SAX	
  or	
  the	
  more	
  efficient	
  XmlPul	
  lParser
Introducing Dialogs


• Answer questions
• Make selections, and
  confirm actions
• Display warning or error
  messages
Implement Dialog

• Using the Dialog class (or its extension)
 ‣   Android	
  includes	
  a	
  number	
  of	
  specialist	
  classes	
  
     that	
  extend	
  Dialog
 ‣   A	
  Dialog-­‐class-­‐based	
  screen	
  is	
  constructed	
  en.rely	
  
     within	
  its	
  calling	
  Ac.vity,	
  so	
  it	
  doesn’t	
  need	
  to	
  be	
  
     registered	
  in	
  the	
  manifest	
  (its	
  life	
  cycle	
  is	
  
     controlled	
  en.rely	
  by	
  the	
  calling	
  Ac.vity)

• Dialog-themed Activities
• Toasts
Introducing the Dialog Classes
The Alert Dialog Class

• Presenting a message to the user
  offering them one to three options in
  the form of buttons (OK, Cancel,Yes
  or No)
• Offering a list of options in the form
  of checkboxes or radio buttons
• Providing a text entry box for user
  input
Alert Dialog used to display a message
and offer two button options to continue
Specialist Input Dialogs


• CharacterPickerDialog
• DatePickerDialog
• TimePickerDialog
• ProgressDialog
Using Activities as Dialogs
•   When: Need more control over the content and
    life cycle of your dialog box
    ‣    The	
  solu.on	
  is	
  to	
  implement	
  it	
  as	
  a	
  full	
  Ac.vity

•   The easiest way to make an Activity look like a
    dialog is to apply the android:style/Theme.Dialog
    theme when you add it to your manifest
•   Cause your Activity to behave as a Dialog, floating
    on top of, and partially obscuring, the Activity
    beneath it
Managing and Displaying Dialogs

• Creating new instances of a dialog
  each time it’s required (☹)
• Android provides the onCreateDialog
  and onPrepareDialog event handlers
  within the Activity class to persist and
  manage dialog-box instances
• showDialog -> onCreateDialog (if
  necessary) -> onPrepareDialog
Thank you :)

Más contenido relacionado

Similar a Ch5 intent broadcast receivers adapters and internet

Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intentsperpetrotech
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfAbdullahMunir32
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development TutorialGermán Bringas
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptBirukMarkos
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 

Similar a Ch5 intent broadcast receivers adapters and internet (20)

Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Basics 4
Basics   4Basics   4
Basics 4
 
Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
Unit - III.pptx
Unit - III.pptxUnit - III.pptx
Unit - III.pptx
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
 
ANDROID
ANDROIDANDROID
ANDROID
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Android - Activity, Services
Android - Activity, ServicesAndroid - Activity, Services
Android - Activity, Services
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development Tutorial
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 
Best android classes in mumbai
Best android classes in mumbaiBest android classes in mumbai
Best android classes in mumbai
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Android intent
Android intentAndroid intent
Android intent
 

Más de Shih-Hsiang Lin

Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageShih-Hsiang Lin
 
Ch6 file, saving states, and preferences
Ch6 file, saving states, and preferencesCh6 file, saving states, and preferences
Ch6 file, saving states, and preferencesShih-Hsiang Lin
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9Shih-Hsiang Lin
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfacesShih-Hsiang Lin
 
Ch3 creating application and activities
Ch3 creating application and activitiesCh3 creating application and activities
Ch3 creating application and activitiesShih-Hsiang Lin
 
[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7Shih-Hsiang Lin
 
[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4Shih-Hsiang Lin
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homographyShih-Hsiang Lin
 
Project Hosting by Google
Project Hosting by GoogleProject Hosting by Google
Project Hosting by GoogleShih-Hsiang Lin
 
An Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelAn Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelShih-Hsiang Lin
 

Más de Shih-Hsiang Lin (13)

Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming Language
 
Ch6 file, saving states, and preferences
Ch6 file, saving states, and preferencesCh6 file, saving states, and preferences
Ch6 file, saving states, and preferences
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfaces
 
Ch3 creating application and activities
Ch3 creating application and activitiesCh3 creating application and activities
Ch3 creating application and activities
 
[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7
 
[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4
 
Function pointer
Function pointerFunction pointer
Function pointer
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homography
 
Git basic
Git basicGit basic
Git basic
 
Project Hosting by Google
Project Hosting by GoogleProject Hosting by Google
Project Hosting by Google
 
An Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelAn Introduction to Hidden Markov Model
An Introduction to Hidden Markov Model
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Ch5 intent broadcast receivers adapters and internet

  • 1. Ch5. Intent, Broadcast Receivers, Adapters, and the internet Browny 16, May, 2011
  • 2. Outline • Introducing Intents • Introducing Adapters • Using Internet Resources • Introducing Dialogs
  • 3. Interaction • Mobile applications on most platforms are isolated from each other, and have strict limitations applied to their interaction with hardware and native components • Android applications use Intents, Broadcast Receivers, Adapters, Content Providers, and the Internet to interact through those boundaries
  • 4. Intents • A message-passing mechanism (within and between applications) • Intents can be used to: ‣ Declare  your  inten.on  that  an  Ac.vity  or  Service   be  started  to  perform  an  ac.on,  usually  with  (or   on)  a  par.cular  piece  of  data ‣ Broadcast  that  an  event  (or  ac.on)  has  occurred ‣ Explicitly  start  a  par.cular  Service  or  Ac.vity
  • 5. Using Intents to Launch Activities • To open an Activity, call startActivity, passing in an Intent ‣ Explicitly  (Explicitly  specify  the  Ac.vity  class  to   open) ‣ Implicitly  (Include  an  ac.on  that  an  Ac.vity   must  perform) • Intent resolution: Decide what activity is chosen to take that action (for implicitly)
  • 6. Explicitly Starting New Activities (1/2) 1. Create a new Intent 2. Specifying the current application Context and Activity class to launch 3. Pass this Intent in to startActivity
  • 7. Explicitly Starting New Activities (2/2) • After startActivity is called, the new Activity will be created and become visible and active, moving to the top of the Activity stack • Calling finish on the new Activity, or pressing the hardware back button, will close it and remove it from the stack
  • 8. Implicit Intents (1/3) • A mechanism that lets anonymous application components service action requests (without knowing exactly which application you’re borrowing functionality from) • Android will at run time resolve it into the Activity class best suited to performing the required action on the type of data specified
  • 9. Implicit Intents (2/3) • Example: Let users make calls from your application ‣ Implement  a  new  dialer  ? ‣ Use  an  implicit  Intent  that  requests  the  ac.on   (dialing)  be  performed  on  a  phone  number
  • 10. Implicit Intents(3/3) • Various native applications provide Activities to handle actions performed on specific data • Third-party applications, including your own, can be registered ‣ To  support  new  ac.ons ‣ To  provide  an  alterna.ve  provider  of  na.ve   ac.ons
  • 11. Returning Results from Activities • startActivity will not provide any feedback • You can start an Activity as a sub- Activity that’s inherently connected to its parent ‣ A  sub-­‐Ac.vity  triggers  an  event  handler  within   its  parent  Ac.vity  when  it  closes   ‣ :  One  Ac.vity  is  providing  data  input   for  another
  • 12. Sub-Activities • Just Activities opened in a different way • Must be registered in the application manifest • Any manifest-registered Activity can be opened as a sub-Activity (system or third-party)
  • 13. Launching Sub-Activities (1/3) • startActivityForResult ‣ Also  pass  in  a  request  code  (will  later  be  used  to   uniquely  iden.fy  the  sub-­‐Ac.vity)
  • 14. Launching Sub-Activities (2/3) • Sub-Activities can be started implicitly or explicitly • When your sub-Activity is ready to return, call setResult before finish to return a result to the calling Activity
  • 15. Launching Sub-Activities(3/3) • The setResult method takes 2 parameters: the result code and the result itself (represented as an Intent) • Example: A sub-Activity’s onCreate method, and shows how an OK and Cancel button might return different results to the calling Activity (next page)
  • 16. If the Activity is closed by the user pressing the hardware back key, or finish is called without a prior call to setResult, the result code will be set to RESULT_CANCELED and the result Intent set to null
  • 17. Handling Sub-Activity Results • When a sub-Activity closes, the onActivityResult event handler is fired within the calling Activity (override this method) • The onActivityResult handler receives a number of parameters ‣ Request  code ‣ Result  code ‣ Data
  • 18.
  • 19. Native Android Actions • Native Android applications also use Intents to launch Activities and sub- Activities • When creating implicit Intents you can use these actions (called Activity Intents) to start Activities and sub- Activities within your own applications ‣ ACTION_ANSWER,  ACTION_CALL,  ACTION_EDIT,   ACTION_PICK,  etc...
  • 20. Using Intent Filters to Service Implicit Intents • How does Android know which application (and component) can service the request ? • Intent Filters are used to register Activities, Services, and Broadcast Receivers as being capable of performing an action on a particular kind of data
  • 21. Registering an Activity as an Intent Receiver(1/2) • Add an <intent-filter> tag to the component’s manifest node using the following tags (and associated attributes) within the Intent Filter node
  • 22. Registering an Activity as an Intent Receiver(2/2) • action ‣ Each  Intent  Filter  must  have  one  (and  only  one)  ac.on   tag.  Ac.ons  should  be  unique  strings  that  are  self-­‐ describing • category ‣ Specify  under  which  circumstances  the  ac.on  should   be  serviced  (ALTERNATIVE,  SELECTIVE_ALTERNATIVE,   BROWSABLE,  etc...) • data ‣ Specify  which  data  types  your  component  can  act  on
  • 23. How Android Resolves Intent Filters 1. Listing all the Intent Filters available from the installed packages 2. Matching the action or category associated with the Intent 3. Matching data 4. If more than one component is resolved from this process all the matching possibilities are offered to the user
  • 24. Using the Launch Intent Within an Activity • When an application component is started through an implicit Intent, it needs to find the action to be performed and the data to be performed on • Use the getData and getAction methods to find the data and action associated with the Intent
  • 25. Passing on Responsibility • Use the startNextMatchingActivity method to pass responsibility for action handling to the next best matching application component
  • 26. Using Intent Filters for Plug-Ins and Extensibility • A plug-in model for your Activities that lets them take advantage of future functionality • Using Intent Filters to populate menus dynamically at run time
  • 27. Supplying Anonymous Actions to Applications (1/2) • Make your Activity’s actions available anonymously for existing applications ‣ Publish  them  using  intent-­‐filter  tags  within  their   manifest  nodes ‣ The  category  tag  must  be  either  ALTERNATIVE   or  SELECTED_ALTERNATIVE  or  both ‣ The  text  used  for  the  Menu  Items  is  specified  by   the  android:label  aVribute
  • 28. Supplying Anonymous Actions to Applications(2/2)
  • 29. Incorporating Anonymous Actions in Your Activity’s Menu ...
  • 30. Introducing Linkify • Linkify is a helper class ‣ Automagically  creates  hyperlinks  within  Text   View  (and  Text  View-­‐derived)  classes  through   RegEx  paVern  matching ‣ Text  that  matches  a  specified  RegEx  paVern  will   be  converted  into  a  clickable  hyperlink ‣ Implicitly  fires  startAc/vity(new  Intent (Intent.ACTION_VIEW,  uri)),  using  the  matched   text  as  the  target  URI
  • 31. The Native Linkify Link Types • How to linkify a Text View to display web and e-mail addresses as hyperlinks • You can also linkify Views from within a layout resource using the android:autoLink attribute
  • 32. Using Intents to Broadcast Events • Intents are capable of sending structured messages across process boundaries • By broadcasting an event using an Intent you let yourself and third-party developers react to events without having to modify your original application • Android uses broadcast Intents to broadcast system events like battery- charging levels, network connections, and incoming calls
  • 33. Broadcasting Events with Intents • Construct the Intent you want to broadcast and use the sendBroadcast method to send it • The Intent action string is used to identify the event being broadcast, so it should be a unique string that identifies the event
  • 34. Broadcast Receivers(1/2) • For a Broadcast Receiver, it needs to be registered, either in code or within the application manifest
  • 35. Broadcast Receivers(2/2) • Applications with Broadcast Receivers registered in the manifest don’t have to be running when the Intent is broadcast for the receivers to execute. They will be started automatically when a matching Intent is broadcast • The five-second execution limit ensures that major processing cannot, and should not, be done within the Broadcast Receiver itself (update content, launch Services, update Activity UI, etc...)
  • 36.
  • 37. Registering Broadcast Receivers in Your Application Manifest Even when the application has been killed or hasn’t been started Only when the application component it is registered within is running
  • 38. Broadcasting Sticky and Ordered Intents • Problem: When broadcasting an Intent using sendBroadcast, your Intent will be received by all registered Broadcast Receivers, but you cannot control the order and they cannot propagate results
  • 39. Native Android Broadcast Actions • You can use these messages to add functionality to your own projects based on system events such as time-zone changes, data-connection status, incoming SMS messages, or phone calls • ACTION_CAMERA_BUTTON, ACTION_SCREEN_OFF, ACTION_TIMEZONE_CHANGED, etc...
  • 40. Pending Intents • The Pending Intent class provides a mechanism for creating Intents that can be fired by another application at a later time • Commonly used to package an Intent that will be fired in response to a future event
  • 41. Introducing Adapters • Adapters are bridging classes that bind data to Views (such as List Views) used in the user interface • Views that support Adapter binding must extend the AdapterView abstract class • You can create your own AdapterView derived controls and to create new Adapter classes to bind them
  • 42. Some Native Adapters • ArrayAdapter ‣ Array  Adapter  uses  the  toString  value  of  each   object  in  the  array  to  create  and  populate  Text   Views • SimpleCursorAdapter ‣ You  specify  an  XML  layout  defini.on,  and  then   bind  each  column  to  a  View  within  that  layout
  • 43. Customizing the Array Adapter • Customize the layout used to represent each View • Extend ArrayAdapter with a type- specific variation, overriding the getView method to assign object properties to layout Views
  • 44.
  • 45. Using Adapters for Data Binding • Apply an Adapter to an AdapterView derived class: Call the View’s setAdapter, passing in an Adapter instance
  • 46. Using Internet Resources • Benefits (client native applications rather than entirely web-based solutions) ‣ Bandwidth:  By  crea.ng  a  na.ve  applica.on  you   can  limit  the  bandwidth  requirements  to  updated   data  only ‣ Caching:  A  na.ve  applica.on  can  cache  data  to   provide  as  much  func.onality  as  possible  without  a   live  connec.on ‣ Na4ve  features:  combine  the  data  available  online   with  the  hardware  features  available  on  the  device
  • 47. Connecting to an Internet Resource • Add an INTERNET uses-permission node to your application manifest ‣ <uses-­‐permission  android:name="android.permission.  INTERNET"  />
  • 48. Using Internet Resources • 2 extreme ‣ Include  a  WebKit-­‐based  browser  View  within  an   Ac.vity ‣ Use  client-­‐side  APIs  to  interact  directly  with   server  processes • Between ‣ Process  remote  XML  feeds  to  extract  and   process  data  using  a  Java-­‐based  XML  parser   such  as  SAX  or  the  more  efficient  XmlPul  lParser
  • 49. Introducing Dialogs • Answer questions • Make selections, and confirm actions • Display warning or error messages
  • 50. Implement Dialog • Using the Dialog class (or its extension) ‣ Android  includes  a  number  of  specialist  classes   that  extend  Dialog ‣ A  Dialog-­‐class-­‐based  screen  is  constructed  en.rely   within  its  calling  Ac.vity,  so  it  doesn’t  need  to  be   registered  in  the  manifest  (its  life  cycle  is   controlled  en.rely  by  the  calling  Ac.vity) • Dialog-themed Activities • Toasts
  • 52. The Alert Dialog Class • Presenting a message to the user offering them one to three options in the form of buttons (OK, Cancel,Yes or No) • Offering a list of options in the form of checkboxes or radio buttons • Providing a text entry box for user input
  • 53. Alert Dialog used to display a message and offer two button options to continue
  • 54. Specialist Input Dialogs • CharacterPickerDialog • DatePickerDialog • TimePickerDialog • ProgressDialog
  • 55. Using Activities as Dialogs • When: Need more control over the content and life cycle of your dialog box ‣ The  solu.on  is  to  implement  it  as  a  full  Ac.vity • The easiest way to make an Activity look like a dialog is to apply the android:style/Theme.Dialog theme when you add it to your manifest • Cause your Activity to behave as a Dialog, floating on top of, and partially obscuring, the Activity beneath it
  • 56. Managing and Displaying Dialogs • Creating new instances of a dialog each time it’s required (☹) • Android provides the onCreateDialog and onPrepareDialog event handlers within the Activity class to persist and manage dialog-box instances • showDialog -> onCreateDialog (if necessary) -> onPrepareDialog