SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
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/

Contenu connexe

Similaire à Android Service Patterns

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 DevelopmentAxway Appcelerator
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseKevin Mas Ruiz
 
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 MeetupMatt Ray
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend FrameworkMike Willbanks
 
20141210 - Microservice Container
20141210 - Microservice Container20141210 - Microservice Container
20141210 - Microservice ContainerJamie (Taka) Wang
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid DoesKevin McMahon
 
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 - FutureJSPhil Leggetter
 
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
 
Transforming to Microservices
Transforming to MicroservicesTransforming to Microservices
Transforming to MicroservicesKyle Brown
 
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.pdfVitulChauhan
 
Microservices: Yes or not?
Microservices: Yes or not?Microservices: Yes or not?
Microservices: Yes or not?Eduard Tomàs
 
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 2014Phil Leggetter
 
Android OS and its Features
Android OS and its FeaturesAndroid OS and its Features
Android OS and its FeaturesHarshad Lokhande
 
Training Bootcamp - MainframeDevOps.pptx
Training Bootcamp - MainframeDevOps.pptxTraining Bootcamp - MainframeDevOps.pptx
Training Bootcamp - MainframeDevOps.pptxNashet Ali
 
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 2014Phil Leggetter
 
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.pdfWessel Loth
 
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 SeattleJim McKeeth
 
Microservices, Spring Cloud & Cloud Foundry
Microservices, Spring Cloud & Cloud FoundryMicroservices, Spring Cloud & Cloud Foundry
Microservices, Spring Cloud & Cloud FoundryEmilio Garcia
 

Similaire à 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
 

Dernier

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
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
 
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
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 

Dernier (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
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
 
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
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 

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/