SlideShare a Scribd company logo
9
Most read
10
Most read
14
Most read
Android Services
Jim McKeeth
Lead Developer Evangelist
Embarcadero Technologies
About Jim McKeeth
• Lead World Wide Developer Evangelist
• Host of Podcast at Delphi.org
• Longtime developer
– Object Pascal, Java, C#, JavaScript, Objective-C, etc.
• Invented and patented swipe to unlock in 2000
– US Patent # 8352745 & 6766456, etc.
• Improvisational performer with ComedySportz Boise
Why Android Services?
• Provide background functionality
• Can run even when app is closed
• Can start on boot or other events
• Can be accessible by multiple apps
Android Services vs. Threads
Android Services
• Cannot access the UI
• Runs in main thread of
host app process
• Can contain multiple
threads
• Used for long running
processes
Threads
• Cannot access the UI
• Not accessible to other
apps
• Terminated with app
• Used to improve
responsiveness
Android Service Type Variations
• IntentService
– Handle asynchronous requests (onHandleIntent(Intent) event)
– Otherwise are syncronous (onStartCommand(Intent) event)
– Both are Bindable (onBind event)
• Local vs. Remote
– Local only accessible by host (exported = false in manifest)
– Remote cross app access (exported = true in manifest)
Android Service Wizard
• Local Service
– Synchronous local access
• Intent Local Service
– Asynchronous local access
• Remote Service
– Synchronous local & remote access
• Intent Remote Service
– Asynchronous local & remote access
Service Class Hierarchy
TDataModule
TAndroidBaseService
Adds OnBind,	OnUnBind,	
OnRebind,	OnTaskRemoved,	
OnConfigurationChanged,	
OnLowMemory,	OnTrimMemory,	
OnHandleMessage*,
JavaService &	JavaIntentService**
TAndroidService
Adds OnStartCommand
TAndroidIntentService
Adds OnHandleIntent
*OnHandleMessage only	
occurs	in	remote	services
**Only	JavaService xor
JavaIntentService will	have	a	
value,	otherwise	nil
Services in Delphi
• The Service is a separate project
• Referenced by, and included in host app
• Must build service before adding to host
• For best results put service in its own directory
How to use a Service
• We have two ways to use a Service:
1. Sending a request (startService(Intent))
It is used to execute an unattended work in background
return START_STICKY or START_REDELIVER_INTENT in OnStartCommand to
restart the service in case the app is closed
2. Bound to the service (bindService)
It is used to create a long-standing connection to interact with the service
3. Can use a combination of both
Service lifecycle
• Lifecycle and events
are different
depending on how
the service is started:
– Started
– Bound
More	information
http://developer.android.com/guide/components/services.html
Restrictions for Services
• Cannot Access UI
• Not use components from the FMX namespace
• Be aware of power consumption
– Using a lot of CPU
– Using network connection
• Respect users expectations and privacy
Service Workarounds
• Use RTL or low-level calls instead of FMX
components. If the service fails when started, use
a lower level call.
• Manually edit manifest to make remote services
published.
• Manually edit Java Templates for Intent and
Remote Services (see http://delphi.org/?p=2084)
DEMONSTRATIONS
Android Services
Summary
• Android services allow for execution even when
app is not running.
• Add a new Android Service project to your app.
• Build service before adding reference.
• More information:
– http://delphi.org/tag/android-services/
– http://embt.co/creating_android_services
– http://embt.co/android_service

More Related Content

PPTX
Future Adaptability of Building Design
PPTX
Yield and Productivity Improvements
PPTX
Gothic architecture
PPT
Rennie Mackintosh
PPTX
Project charter sample
PPT
Gothic Architecture
PPTX
Sintesis:Película Sin Límites
PDF
Escuela de glasgow
Future Adaptability of Building Design
Yield and Productivity Improvements
Gothic architecture
Rennie Mackintosh
Project charter sample
Gothic Architecture
Sintesis:Película Sin Límites
Escuela de glasgow

What's hot (6)

PDF
Karl valenti-o-aguário
PPTX
Frank Lloyd Wright Architecture
PDF
Altonaer strasse 4-14, Hansaviertel, Oscar Niemeyer
PPTX
Organizational agility
PDF
Michael Vidyakin: Defining PMO Structure and Governance (UA)
PPTX
Richard neutra (1892-1970)
Karl valenti-o-aguário
Frank Lloyd Wright Architecture
Altonaer strasse 4-14, Hansaviertel, Oscar Niemeyer
Organizational agility
Michael Vidyakin: Defining PMO Structure and Governance (UA)
Richard neutra (1892-1970)
Ad

Viewers also liked (20)

PDF
Android Services Skill Sprint
PDF
Deep Dive into Futures and the Parallel Programming Library
ODP
Android App Development - 08 Services
PDF
Android M - Runtime Permissions | Getting ready for Marshmallow
PDF
Android interview questions
PPTX
Interview questions for an Android Developer
PPTX
Porting Flickr to YUI3 - F2E Summit
ODP
PPT
Financial analyst
PDF
PDF
"Продвигайте игровые приложения с Google", Санджар Исмаилов, Infudtry Manage...
DOCX
4 introduccion a la ingenieria pag 37-40
PPT
De kleren van_sinterklaas
PDF
T2_e2_rodriguez-noemi
PDF
Economic Development Update - Garrett County, MD (09.24.2013)
PPSX
PDF
Status Board 面白いよ!
Android Services Skill Sprint
Deep Dive into Futures and the Parallel Programming Library
Android App Development - 08 Services
Android M - Runtime Permissions | Getting ready for Marshmallow
Android interview questions
Interview questions for an Android Developer
Porting Flickr to YUI3 - F2E Summit
Financial analyst
"Продвигайте игровые приложения с Google", Санджар Исмаилов, Infudtry Manage...
4 introduccion a la ingenieria pag 37-40
De kleren van_sinterklaas
T2_e2_rodriguez-noemi
Economic Development Update - Garrett County, MD (09.24.2013)
Status Board 面白いよ!
Ad

Similar to Creating Android Services with Delphi and RAD Studio 10 Seattle (20)

PDF
Explore Android Internals
PPTX
Introduction to Android Development
PPTX
Unit No. II Architecture.pptx Cloud Microservices & Application
PPTX
Intro to Microservices Architecture
PPTX
What serverless means for enterprise apps
PDF
Chat application throught client server project report.pdf
PDF
CNIT 128 7. Attacking Android Applications (Part 2)
PPT
Module - Programming with android course.ppt
PDF
Chat application through client server management system project.pdf
PPTX
Creative Automation with Galen Framework
PDF
Fed London - January 2015
PPTX
Microservices: Yes or not?
PPTX
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
PPTX
Basics 4
PDF
How to Build Front-End Web Apps that Scale - FutureJS
PDF
CNIT 128 7. Attacking Android Applications (Part 2)
PDF
Microservice Architecture Patterns, by Richard Langlois P. Eng.
PPT
4. system models
PDF
7. Attacking Android Applications (Part 2)
DOC
Lakkakula Sunil Kumar
Explore Android Internals
Introduction to Android Development
Unit No. II Architecture.pptx Cloud Microservices & Application
Intro to Microservices Architecture
What serverless means for enterprise apps
Chat application throught client server project report.pdf
CNIT 128 7. Attacking Android Applications (Part 2)
Module - Programming with android course.ppt
Chat application through client server management system project.pdf
Creative Automation with Galen Framework
Fed London - January 2015
Microservices: Yes or not?
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Basics 4
How to Build Front-End Web Apps that Scale - FutureJS
CNIT 128 7. Attacking Android Applications (Part 2)
Microservice Architecture Patterns, by Richard Langlois P. Eng.
4. system models
7. Attacking Android Applications (Part 2)
Lakkakula Sunil Kumar

More from Jim McKeeth (15)

PDF
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
PDF
Announcing Codolex 2.0 from GDK Software
PDF
Smart Contracts - The Blockchain Beyond Bitcoin
PDF
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
PDF
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
PDF
Day 5 of C++ Boot Camp - Stepping Up to Mobile
PDF
Building a Thought Controlled Drone
PDF
Embarcadero's Connected Development
PDF
The Internet of Things and You - A Developers Guide to IoT
PDF
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
PDF
Android voice skill sprint
PDF
Exploring the Brain Computer Interface
PDF
Introduction to Android Development with Java
PDF
Hacking iBooks and ePub3 with JavaScript!
PDF
Inventing merit badge
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
Announcing Codolex 2.0 from GDK Software
Smart Contracts - The Blockchain Beyond Bitcoin
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
Day 5 of C++ Boot Camp - Stepping Up to Mobile
Building a Thought Controlled Drone
Embarcadero's Connected Development
The Internet of Things and You - A Developers Guide to IoT
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Android voice skill sprint
Exploring the Brain Computer Interface
Introduction to Android Development with Java
Hacking iBooks and ePub3 with JavaScript!
Inventing merit badge

Recently uploaded (20)

PPTX
Introduction to Artificial Intelligence
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
AI in Product Development-omnex systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
System and Network Administraation Chapter 3
PDF
medical staffing services at VALiNTRY
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Essential Infomation Tech presentation.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ai tools demonstartion for schools and inter college
Introduction to Artificial Intelligence
VVF-Customer-Presentation2025-Ver1.9.pptx
Digital Strategies for Manufacturing Companies
Upgrade and Innovation Strategies for SAP ERP Customers
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
CHAPTER 2 - PM Management and IT Context
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
AI in Product Development-omnex systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Which alternative to Crystal Reports is best for small or large businesses.pdf
System and Network Administraation Chapter 3
medical staffing services at VALiNTRY
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Essential Infomation Tech presentation.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ai tools demonstartion for schools and inter college

Creating Android Services with Delphi and RAD Studio 10 Seattle

  • 1. Android Services Jim McKeeth Lead Developer Evangelist Embarcadero Technologies
  • 2. About Jim McKeeth • Lead World Wide Developer Evangelist • Host of Podcast at Delphi.org • Longtime developer – Object Pascal, Java, C#, JavaScript, Objective-C, etc. • Invented and patented swipe to unlock in 2000 – US Patent # 8352745 & 6766456, etc. • Improvisational performer with ComedySportz Boise
  • 3. Why Android Services? • Provide background functionality • Can run even when app is closed • Can start on boot or other events • Can be accessible by multiple apps
  • 4. Android Services vs. Threads Android Services • Cannot access the UI • Runs in main thread of host app process • Can contain multiple threads • Used for long running processes Threads • Cannot access the UI • Not accessible to other apps • Terminated with app • Used to improve responsiveness
  • 5. Android Service Type Variations • IntentService – Handle asynchronous requests (onHandleIntent(Intent) event) – Otherwise are syncronous (onStartCommand(Intent) event) – Both are Bindable (onBind event) • Local vs. Remote – Local only accessible by host (exported = false in manifest) – Remote cross app access (exported = true in manifest)
  • 6. Android Service Wizard • Local Service – Synchronous local access • Intent Local Service – Asynchronous local access • Remote Service – Synchronous local & remote access • Intent Remote Service – Asynchronous local & remote access
  • 7. Service Class Hierarchy TDataModule TAndroidBaseService Adds OnBind, OnUnBind, OnRebind, OnTaskRemoved, OnConfigurationChanged, OnLowMemory, OnTrimMemory, OnHandleMessage*, JavaService & JavaIntentService** TAndroidService Adds OnStartCommand TAndroidIntentService Adds OnHandleIntent *OnHandleMessage only occurs in remote services **Only JavaService xor JavaIntentService will have a value, otherwise nil
  • 8. Services in Delphi • The Service is a separate project • Referenced by, and included in host app • Must build service before adding to host • For best results put service in its own directory
  • 9. How to use a Service • We have two ways to use a Service: 1. Sending a request (startService(Intent)) It is used to execute an unattended work in background return START_STICKY or START_REDELIVER_INTENT in OnStartCommand to restart the service in case the app is closed 2. Bound to the service (bindService) It is used to create a long-standing connection to interact with the service 3. Can use a combination of both
  • 10. Service lifecycle • Lifecycle and events are different depending on how the service is started: – Started – Bound More information http://developer.android.com/guide/components/services.html
  • 11. Restrictions for Services • Cannot Access UI • Not use components from the FMX namespace • Be aware of power consumption – Using a lot of CPU – Using network connection • Respect users expectations and privacy
  • 12. Service Workarounds • Use RTL or low-level calls instead of FMX components. If the service fails when started, use a lower level call. • Manually edit manifest to make remote services published. • Manually edit Java Templates for Intent and Remote Services (see http://delphi.org/?p=2084)
  • 14. Summary • Android services allow for execution even when app is not running. • Add a new Android Service project to your app. • Build service before adding reference. • More information: – http://delphi.org/tag/android-services/ – http://embt.co/creating_android_services – http://embt.co/android_service