SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
Android Service Patterns
  AIDL Services Aren’t That Hard…
          Shree Kumar
          InnoMinds Software
Motivation
 • Writing services is useful & fun
       – Not to mention, painful !
 • Documentation is present, but…
       – Scattered
       – Deals mostly with mechanics
 • Can a 45 minute session make a difference ?
Android Service Patterns | DroidCon India 2011
Objectives
 • Clarification on the term “Patterns”
       – NOT design patterns a-la Grady Booch!
 • This talk gives you
       – Quick overview of AIDL based Services
       – Features & Pains
       – Writing useful services as patterns

Android Service Patterns | DroidCon India 2011
Intro to Android Services
 • The “Service” concept
       – Application component
       – Typically used for long-running operations
       – Does not automatically create
             • new processes or threads
 • Can be roughly classified based on
       – Interaction Mechanism : Started, Bound
       – Application Boundaries : In-process, IPC

Android Service Patterns | DroidCon India 2011
AIDL based IPC Services
 • Android Interface Definition Language
 • Inter-Process Communication to
       – Expose interfaces to other applications
 • More complicated than “Messenger”



Android Service Patterns | DroidCon India 2011
Why all the pain?
 • “natural” interactions with the service
       – Calls & callbacks
       – With complex objects as parameters
 • And all these across process boundaries!



Android Service Patterns | DroidCon India 2011
Hello, AIDL Service!
 • Implements onBind()
       – Exposes interface by implementing stubs
 • Exports via AndroidManifest.xml
 • Client apps bind via Intents
       – Use interface methods
       – Callbacks require app to implement stubs
         corresponding to callback interface

Android Service Patterns | DroidCon India 2011
What’s not-so-nice there ?
 • No control over binding
       – onBind() return value is cached!
 • No control over threading
 • Code messier than in-process interface
       – No support for exceptions
       – Dead remote object exceptions => messy code
       – Callbacks not invoked in UI context
 • No concept of versioning

Android Service Patterns | DroidCon India 2011
Common Service Patterns
 • Exclusive access to shared resource
       – The “lock” pattern
 • Simultaneous access to shared resource
       – “serialize”, “broadcast” patterns
 • Less common
       – Service versioning
       – Multiple objects of the same type
Android Service Patterns | DroidCon India 2011
The “lock” pattern
 • Exclusive access using “locks”
       – Take lock before use
       – Release lock after use
 • Looks simple ?
       – Multi-app access
       – Appropriate threading model
       – Improper app lock handling => starvation

Android Service Patterns | DroidCon India 2011
Locked Service Implementation
 • Associate locks with calling process
 • Worker thread for serialization
       – Started on service creation
       – Producer-consumer modeling
             • Java.util.concurrent provides ample support
 • Partial solution for starvation
       – Evict clients on DeadObjectException

Android Service Patterns | DroidCon India 2011
Shared Access Service
 • “broadcast” method
       – Shares a state update with multiple listeners
       – Broadcast receivers don’t make the cut
             • Can’t bind a Service inside them
 • Implementation
       – Reuse “listener” concept
             • Clients add/remove listeners
       – Service maintains list of listeners
             • Updates listeners when needed
             • Removes dead objects
       – Reference : MindTheRobot Android Architecture Tutorial

Android Service Patterns | DroidCon India 2011
Questions ?
   Shree Kumar
   shree.shree@gmail.com
http:://www.shreekumar.in/

Weitere ähnliche Inhalte

Ähnlich wie Android Service Patterns

20141210 - Microservice Container
20141210 - Microservice Container20141210 - Microservice Container
20141210 - Microservice Container
Jamie (Taka) Wang
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 
Training Bootcamp - MainframeDevOps.pptx
Training Bootcamp - MainframeDevOps.pptxTraining Bootcamp - MainframeDevOps.pptx
Training Bootcamp - MainframeDevOps.pptx
Nashet Ali
 
Microservices, Spring Cloud & Cloud Foundry
Microservices, Spring Cloud & Cloud FoundryMicroservices, Spring Cloud & Cloud Foundry
Microservices, Spring Cloud & Cloud Foundry
Emilio Garcia
 

Ähnlich wie Android Service Patterns (20)

Kevin Whinnery: Best Practices for Cross-Platform Mobile Development
Kevin Whinnery: Best Practices for Cross-Platform Mobile DevelopmentKevin Whinnery: Best Practices for Cross-Platform Mobile Development
Kevin Whinnery: Best Practices for Cross-Platform Mobile Development
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD Course
 
Automating Applications with Habitat - Sydney Cloud Native Meetup
Automating Applications with Habitat - Sydney Cloud Native MeetupAutomating Applications with Habitat - Sydney Cloud Native Meetup
Automating Applications with Habitat - Sydney Cloud Native Meetup
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend Framework
 
20141210 - Microservice Container
20141210 - Microservice Container20141210 - Microservice Container
20141210 - Microservice Container
 
Testing banking apps
Testing banking appsTesting banking apps
Testing banking apps
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid Does
 
How to Build Front-End Web Apps that Scale - FutureJS
How to Build Front-End Web Apps that Scale - FutureJSHow to Build Front-End Web Apps that Scale - FutureJS
How to Build Front-End Web Apps that Scale - FutureJS
 
Mule ESB Intro
Mule ESB IntroMule ESB Intro
Mule ESB Intro
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
Transforming to Microservices
Transforming to MicroservicesTransforming to Microservices
Transforming to Microservices
 
Internship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdf
Internship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdfInternship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdf
Internship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdf
 
Microservices: Yes or not?
Microservices: Yes or not?Microservices: Yes or not?
Microservices: Yes or not?
 
Building front-end apps that Scale - FOSDEM 2014
Building front-end apps that Scale - FOSDEM 2014Building front-end apps that Scale - FOSDEM 2014
Building front-end apps that Scale - FOSDEM 2014
 
Android OS and its Features
Android OS and its FeaturesAndroid OS and its Features
Android OS and its Features
 
Training Bootcamp - MainframeDevOps.pptx
Training Bootcamp - MainframeDevOps.pptxTraining Bootcamp - MainframeDevOps.pptx
Training Bootcamp - MainframeDevOps.pptx
 
Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
Using BladeRunnerJS to Build Front-End Apps that Scale - Fluent 2014
 
Wessel Loth - Fire your Frontend Framework with Lit - TEQnation 2022.pdf
Wessel Loth - Fire your Frontend Framework with Lit - TEQnation 2022.pdfWessel Loth - Fire your Frontend Framework with Lit - TEQnation 2022.pdf
Wessel Loth - Fire your Frontend Framework with Lit - TEQnation 2022.pdf
 
Creating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleCreating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 Seattle
 
Microservices, Spring Cloud & Cloud Foundry
Microservices, Spring Cloud & Cloud FoundryMicroservices, Spring Cloud & Cloud Foundry
Microservices, Spring Cloud & Cloud Foundry
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Android Service Patterns

  • 1. Android Service Patterns AIDL Services Aren’t That Hard… Shree Kumar InnoMinds Software
  • 2. Motivation • Writing services is useful & fun – Not to mention, painful ! • Documentation is present, but… – Scattered – Deals mostly with mechanics • Can a 45 minute session make a difference ? Android Service Patterns | DroidCon India 2011
  • 3. Objectives • Clarification on the term “Patterns” – NOT design patterns a-la Grady Booch! • This talk gives you – Quick overview of AIDL based Services – Features & Pains – Writing useful services as patterns Android Service Patterns | DroidCon India 2011
  • 4. Intro to Android Services • The “Service” concept – Application component – Typically used for long-running operations – Does not automatically create • new processes or threads • Can be roughly classified based on – Interaction Mechanism : Started, Bound – Application Boundaries : In-process, IPC Android Service Patterns | DroidCon India 2011
  • 5. AIDL based IPC Services • Android Interface Definition Language • Inter-Process Communication to – Expose interfaces to other applications • More complicated than “Messenger” Android Service Patterns | DroidCon India 2011
  • 6. Why all the pain? • “natural” interactions with the service – Calls & callbacks – With complex objects as parameters • And all these across process boundaries! Android Service Patterns | DroidCon India 2011
  • 7. Hello, AIDL Service! • Implements onBind() – Exposes interface by implementing stubs • Exports via AndroidManifest.xml • Client apps bind via Intents – Use interface methods – Callbacks require app to implement stubs corresponding to callback interface Android Service Patterns | DroidCon India 2011
  • 8. What’s not-so-nice there ? • No control over binding – onBind() return value is cached! • No control over threading • Code messier than in-process interface – No support for exceptions – Dead remote object exceptions => messy code – Callbacks not invoked in UI context • No concept of versioning Android Service Patterns | DroidCon India 2011
  • 9. Common Service Patterns • Exclusive access to shared resource – The “lock” pattern • Simultaneous access to shared resource – “serialize”, “broadcast” patterns • Less common – Service versioning – Multiple objects of the same type Android Service Patterns | DroidCon India 2011
  • 10. The “lock” pattern • Exclusive access using “locks” – Take lock before use – Release lock after use • Looks simple ? – Multi-app access – Appropriate threading model – Improper app lock handling => starvation Android Service Patterns | DroidCon India 2011
  • 11. Locked Service Implementation • Associate locks with calling process • Worker thread for serialization – Started on service creation – Producer-consumer modeling • Java.util.concurrent provides ample support • Partial solution for starvation – Evict clients on DeadObjectException Android Service Patterns | DroidCon India 2011
  • 12. Shared Access Service • “broadcast” method – Shares a state update with multiple listeners – Broadcast receivers don’t make the cut • Can’t bind a Service inside them • Implementation – Reuse “listener” concept • Clients add/remove listeners – Service maintains list of listeners • Updates listeners when needed • Removes dead objects – Reference : MindTheRobot Android Architecture Tutorial Android Service Patterns | DroidCon India 2011
  • 13. Questions ? Shree Kumar shree.shree@gmail.com http:://www.shreekumar.in/