SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque (15)

Polímeros
PolímerosPolímeros
Polímeros
 
Porting Flickr to YUI3 - F2E Summit
Porting Flickr to YUI3 - F2E SummitPorting Flickr to YUI3 - F2E Summit
Porting Flickr to YUI3 - F2E Summit
 
Watchmen
WatchmenWatchmen
Watchmen
 
Financial analyst
Financial analystFinancial analyst
Financial analyst
 
Young1928
Young1928Young1928
Young1928
 
Web & Sostenibilità
Web & SostenibilitàWeb & Sostenibilità
Web & Sostenibilità
 
"Продвигайте игровые приложения с Google", Санджар Исмаилов, Infudtry Manage...
"Продвигайте игровые приложения с Google", Санджар Исмаилов, Infudtry Manage..."Продвигайте игровые приложения с Google", Санджар Исмаилов, Infudtry Manage...
"Продвигайте игровые приложения с Google", Санджар Исмаилов, Infudtry Manage...
 
4 introduccion a la ingenieria pag 37-40
4 introduccion a la ingenieria pag 37-404 introduccion a la ingenieria pag 37-40
4 introduccion a la ingenieria pag 37-40
 
De kleren van_sinterklaas
De kleren van_sinterklaasDe kleren van_sinterklaas
De kleren van_sinterklaas
 
AssoSCAI @brianzaamica
AssoSCAI @brianzaamicaAssoSCAI @brianzaamica
AssoSCAI @brianzaamica
 
T2_e2_rodriguez-noemi
T2_e2_rodriguez-noemiT2_e2_rodriguez-noemi
T2_e2_rodriguez-noemi
 
Economic Development Update - Garrett County, MD (09.24.2013)
Economic Development Update - Garrett County, MD (09.24.2013)Economic Development Update - Garrett County, MD (09.24.2013)
Economic Development Update - Garrett County, MD (09.24.2013)
 
Silicon Valley trip
Silicon Valley tripSilicon Valley trip
Silicon Valley trip
 
Status Board 面白いよ!
Status Board 面白いよ!Status Board 面白いよ!
Status Board 面白いよ!
 
It's not just about Apps
It's not just about AppsIt's not just about Apps
It's not just about Apps
 

Semelhante a Creating Android Services with Delphi and RAD Studio 10 Seattle

Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentOwain Lewis
 
Intro to Microservices Architecture
Intro to Microservices ArchitectureIntro to Microservices Architecture
Intro to Microservices ArchitecturePeter Nijem
 
What serverless means for enterprise apps
What serverless means for enterprise appsWhat serverless means for enterprise apps
What serverless means for enterprise appsSumit Sarkar
 
CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)Sam Bowne
 
Creative Automation with Galen Framework
Creative Automation with Galen FrameworkCreative Automation with Galen Framework
Creative Automation with Galen Framework'Ashmeet Sehgal'
 
Fed London - January 2015
Fed London - January 2015Fed London - January 2015
Fed London - January 2015Phil Leggetter
 
Microservices: Yes or not?
Microservices: Yes or not?Microservices: Yes or not?
Microservices: Yes or not?Eduard Tomàs
 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Atharva Jawalkar
 
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
 
CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)Sam Bowne
 
Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.Richard Langlois P. Eng.
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)Sam Bowne
 
Twelve Factor App With Lagom
Twelve Factor App With LagomTwelve Factor App With Lagom
Twelve Factor App With LagomKnoldus Inc.
 
Yotpo microservices
Yotpo microservicesYotpo microservices
Yotpo microservicesRon Barabash
 
MICROSERVICES ARCHITECTURE unit -2.pptx
MICROSERVICES ARCHITECTURE unit -2.pptxMICROSERVICES ARCHITECTURE unit -2.pptx
MICROSERVICES ARCHITECTURE unit -2.pptxMohammedShahid562503
 

Semelhante a Creating Android Services with Delphi and RAD Studio 10 Seattle (20)

Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Intro to Microservices Architecture
Intro to Microservices ArchitectureIntro to Microservices Architecture
Intro to Microservices Architecture
 
What serverless means for enterprise apps
What serverless means for enterprise appsWhat serverless means for enterprise apps
What serverless means for enterprise apps
 
CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)
 
Creative Automation with Galen Framework
Creative Automation with Galen FrameworkCreative Automation with Galen Framework
Creative Automation with Galen Framework
 
Fed London - January 2015
Fed London - January 2015Fed London - January 2015
Fed London - January 2015
 
Microservices: Yes or not?
Microservices: Yes or not?Microservices: Yes or not?
Microservices: Yes or not?
 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
 
Basics 4
Basics   4Basics   4
Basics 4
 
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
 
CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)CNIT 128 7. Attacking Android Applications (Part 2)
CNIT 128 7. Attacking Android Applications (Part 2)
 
Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.
 
4. system models
4. system models4. system models
4. system models
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)
 
Lakkakula Sunil Kumar
Lakkakula Sunil KumarLakkakula Sunil Kumar
Lakkakula Sunil Kumar
 
Twelve Factor App With Lagom
Twelve Factor App With LagomTwelve Factor App With Lagom
Twelve Factor App With Lagom
 
Microservices
MicroservicesMicroservices
Microservices
 
Yotpo microservices
Yotpo microservicesYotpo microservices
Yotpo microservices
 
MICROSERVICES ARCHITECTURE unit -2.pptx
MICROSERVICES ARCHITECTURE unit -2.pptxMICROSERVICES ARCHITECTURE unit -2.pptx
MICROSERVICES ARCHITECTURE unit -2.pptx
 

Mais de Jim McKeeth

Smart Contracts - The Blockchain Beyond Bitcoin
Smart Contracts - The Blockchain Beyond BitcoinSmart Contracts - The Blockchain Beyond Bitcoin
Smart Contracts - The Blockchain Beyond BitcoinJim McKeeth
 
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Rapid Prototyping Mobile IoT Projects with Arduino and Open HardwareRapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Rapid Prototyping Mobile IoT Projects with Arduino and Open HardwareJim McKeeth
 
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
Day 3 of C++ Boot Camp - C++11 Language Deep DiveDay 3 of C++ Boot Camp - C++11 Language Deep Dive
Day 3 of C++ Boot Camp - C++11 Language Deep DiveJim McKeeth
 
Day 5 of C++ Boot Camp - Stepping Up to Mobile
Day 5 of C++ Boot Camp - Stepping Up to MobileDay 5 of C++ Boot Camp - Stepping Up to Mobile
Day 5 of C++ Boot Camp - Stepping Up to MobileJim McKeeth
 
Building a Thought Controlled Drone
Building a Thought Controlled DroneBuilding a Thought Controlled Drone
Building a Thought Controlled DroneJim McKeeth
 
Embarcadero's Connected Development
Embarcadero's Connected DevelopmentEmbarcadero's Connected Development
Embarcadero's Connected DevelopmentJim McKeeth
 
The Internet of Things and You - A Developers Guide to IoT
The Internet of Things and You - A Developers Guide to IoTThe Internet of Things and You - A Developers Guide to IoT
The Internet of Things and You - A Developers Guide to IoTJim McKeeth
 
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...Jim McKeeth
 
Android voice skill sprint
Android voice skill sprintAndroid voice skill sprint
Android voice skill sprintJim McKeeth
 
Exploring the Brain Computer Interface
Exploring the Brain Computer InterfaceExploring the Brain Computer Interface
Exploring the Brain Computer InterfaceJim McKeeth
 
Introduction to Android Development with Java
Introduction to Android Development with JavaIntroduction to Android Development with Java
Introduction to Android Development with JavaJim McKeeth
 
Hacking iBooks and ePub3 with JavaScript!
Hacking iBooks and ePub3 with JavaScript!Hacking iBooks and ePub3 with JavaScript!
Hacking iBooks and ePub3 with JavaScript!Jim McKeeth
 
Inventing merit badge
Inventing merit badgeInventing merit badge
Inventing merit badgeJim McKeeth
 

Mais de Jim McKeeth (13)

Smart Contracts - The Blockchain Beyond Bitcoin
Smart Contracts - The Blockchain Beyond BitcoinSmart Contracts - The Blockchain Beyond Bitcoin
Smart Contracts - The Blockchain Beyond Bitcoin
 
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Rapid Prototyping Mobile IoT Projects with Arduino and Open HardwareRapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
 
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
Day 3 of C++ Boot Camp - C++11 Language Deep DiveDay 3 of C++ Boot Camp - C++11 Language Deep Dive
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
 
Day 5 of C++ Boot Camp - Stepping Up to Mobile
Day 5 of C++ Boot Camp - Stepping Up to MobileDay 5 of C++ Boot Camp - Stepping Up to Mobile
Day 5 of C++ Boot Camp - Stepping Up to Mobile
 
Building a Thought Controlled Drone
Building a Thought Controlled DroneBuilding a Thought Controlled Drone
Building a Thought Controlled Drone
 
Embarcadero's Connected Development
Embarcadero's Connected DevelopmentEmbarcadero's Connected Development
Embarcadero's Connected Development
 
The Internet of Things and You - A Developers Guide to IoT
The Internet of Things and You - A Developers Guide to IoTThe Internet of Things and You - A Developers Guide to IoT
The Internet of Things and You - A Developers Guide to IoT
 
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
 
Android voice skill sprint
Android voice skill sprintAndroid voice skill sprint
Android voice skill sprint
 
Exploring the Brain Computer Interface
Exploring the Brain Computer InterfaceExploring the Brain Computer Interface
Exploring the Brain Computer Interface
 
Introduction to Android Development with Java
Introduction to Android Development with JavaIntroduction to Android Development with Java
Introduction to Android Development with Java
 
Hacking iBooks and ePub3 with JavaScript!
Hacking iBooks and ePub3 with JavaScript!Hacking iBooks and ePub3 with JavaScript!
Hacking iBooks and ePub3 with JavaScript!
 
Inventing merit badge
Inventing merit badgeInventing merit badge
Inventing merit badge
 

Último

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 

Último (20)

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 

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