SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
Android Service
Topics
• What is a Service?
• Service lifecycles
• Permissions
• Local services
• Remote services
What is a Service?
When a Service Used?
• Applications will need to run processes for a
long time without any intervention from the
user, or very rare interventions.
• These background processes need to keep
running even when the phone is being used for
other activities / tasks.
Two Types of Services
• Local service
> Not accessible from other applications
> Runs in the same process of the application that
starts it
• Remote service
> Accessible from other applications as well
> Exposes to other applications through AIDL (Android
Services Definition Language)
Service and Notification
• Service is a long lived component and does not
implement any user interface of its own.
> Typically a user interacts with a service through an
activity that has a UI.
• The service “notifies” the user in case of any
need for user intervention.
> Through the notification (such as status bar
notification), the service can give a user interface for
binding to the service or viewing the status of the
service or any other similar interaction with the
service.
What Facilities Service Provide?
• A facility for the application to tell the system
about something it wants to be doing in the
background (even when the user is not directly
interacting with the application).
> This corresponds to calls to Context.startService(),
which ask the system to schedule work for the
service, to be run until the service or someone else
explicitly stop it.
• A facility for an application to expose some of
its functionality to other applications.
> This corresponds to calls to Context.bindService(),
which allows a long-standing connection to be made
to the service in order to interact with it.
Binding to a Service
• Once a service has begun and is running in the
background, activities can “bind” to the service.
> In fact, if we want to bind to a service that has not
started, calling to bind could initiate the service.
Service Lifecycle
Starting a Service
• If someone calls Context.startService() then the
system will retrieve the service (creating it and
calling its onCreate() method if needed) and
then call its onStartCommand(Intent, int, int)
method with the arguments supplied by the
client.
• The service will at this point continue running
until Context.stopService() or stopSelf() is
called.
Modes of Operations
• For started services, there are two additional
major modes of operation they can decide to
run in, depending on the value they return from
onStartCommand():
> START_STICKY is used for services that are explicitly
started and stopped as needed,
> START_NOT_STICKY or START_REDELIVER_INTENT
are used for services that should only remain running
while processing any commands sent to them.
Getting a Connection to a Service
• Clients can also use Context.bindService() to
obtain a persistent connection to a service.
> This likewise creates the service if it is not already
running (calling onCreate() while doing so), but does
not call onStartCommand().
• The client will receive the IBinder object that
the service returns from its onBind(Intent)
method, allowing the client to then make calls
back to the service.
Permissions
Permissions
• Global access to a service can be enforced
when it is declared in its manifest's <service>
tag.
• By doing so, other applications will need to
declare a corresponding <uses-permission>
element in their own manifest to be able to
start, stop, or bind to the service.
• In addition, a service can protect individual IPC
calls into it with permissions, by calling the
checkCallingPermission(String) method before
executing the implementation of that call.
Local Service Sample
Local Service
• One of the most common uses of a Service is as
a secondary component running alongside
other parts of an application, in the same
process as the rest of the components.
> All components of an .apk run in the same process
unless explicitly stated otherwise, so this is a typical
situation.
• When used in this way, by assuming the
components are in the same process, you can
greatly simplify the interaction between them
> Clients of the service can simply cast the IBinder
they receive from it to a concrete class published by
the service.
Remote Messenger Service
Remote Messenger Service
• If you need to be able to write a Service that
can perform complicated communication with
clients in remote processes (beyond simply the
use of Context.startService to send commands
to it), then you can use the Messenger class
instead of writing full AIDL files.
Thank you

Mais conteúdo relacionado

Destaque

Todo trabajo es temporal
Todo trabajo es temporalTodo trabajo es temporal
Todo trabajo es temporalAndroid UNAM
 
Android de la A a la Z Actividades ulises gonzalez
Android de la A a la Z   Actividades ulises gonzalezAndroid de la A a la Z   Actividades ulises gonzalez
Android de la A a la Z Actividades ulises gonzalezAndroid UNAM
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises GonzalezAndroid UNAM
 
Curso Taller Android Procesado Imagen
Curso Taller Android Procesado ImagenCurso Taller Android Procesado Imagen
Curso Taller Android Procesado ImagenEmilio Aviles Avila
 
operaciones aritméticas usando
operaciones aritméticas  usando operaciones aritméticas  usando
operaciones aritméticas usando Sarahi Garcia Ruiz
 
ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2
ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2
ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2Jacinto Cabrera Rodríguez
 
Desarrollo android - 6 - multimedia
Desarrollo android - 6 - multimediaDesarrollo android - 6 - multimedia
Desarrollo android - 6 - multimediaEmilio Aviles Avila
 
Intro. a Android Instituto Bosc de la Coma en Olot
Intro. a Android Instituto Bosc de la Coma en OlotIntro. a Android Instituto Bosc de la Coma en Olot
Intro. a Android Instituto Bosc de la Coma en Olothojalataverde
 
BDJ Team_Oct2015_pg_BADT
BDJ Team_Oct2015_pg_BADTBDJ Team_Oct2015_pg_BADT
BDJ Team_Oct2015_pg_BADTJulie Bissett
 
Interfaces increibles en Android
Interfaces increibles en AndroidInterfaces increibles en Android
Interfaces increibles en Androidjezabelink
 
Desarrollo en Android: Conceptos Básicos
Desarrollo en Android: Conceptos BásicosDesarrollo en Android: Conceptos Básicos
Desarrollo en Android: Conceptos BásicosGabriel Huecas
 
Sincronización de BD SQLite con MySQL en Android
Sincronización de BD SQLite con MySQL en AndroidSincronización de BD SQLite con MySQL en Android
Sincronización de BD SQLite con MySQL en AndroidMeison Chirinos
 
Education and Management of Diabetics
Education and Management of DiabeticsEducation and Management of Diabetics
Education and Management of DiabeticsDalia A. Hamdy
 
Diseño de interfaces móviles (UX y la arquitectura de software)
Diseño de interfaces móviles (UX y la arquitectura de software)Diseño de interfaces móviles (UX y la arquitectura de software)
Diseño de interfaces móviles (UX y la arquitectura de software)jezabelink
 
Bases de Datos en Android y Desarrollo de Aplicaciones Móviles Multiplataforma
Bases de Datos en Android y Desarrollo de Aplicaciones Móviles MultiplataformaBases de Datos en Android y Desarrollo de Aplicaciones Móviles Multiplataforma
Bases de Datos en Android y Desarrollo de Aplicaciones Móviles MultiplataformaUniversidad Autonoma de Chihuahua
 

Destaque (20)

Todo trabajo es temporal
Todo trabajo es temporalTodo trabajo es temporal
Todo trabajo es temporal
 
Android de la A a la Z Actividades ulises gonzalez
Android de la A a la Z   Actividades ulises gonzalezAndroid de la A a la Z   Actividades ulises gonzalez
Android de la A a la Z Actividades ulises gonzalez
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises Gonzalez
 
Curso Taller Android Procesado Imagen
Curso Taller Android Procesado ImagenCurso Taller Android Procesado Imagen
Curso Taller Android Procesado Imagen
 
operaciones aritméticas usando
operaciones aritméticas  usando operaciones aritméticas  usando
operaciones aritméticas usando
 
Android: Interfaz de Usuario
Android: Interfaz de UsuarioAndroid: Interfaz de Usuario
Android: Interfaz de Usuario
 
ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2
ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2
ESTRUCTURA DE UN PROYECTO EN ANDROID STUDIO 2.2
 
Desarrollo android - 6 - multimedia
Desarrollo android - 6 - multimediaDesarrollo android - 6 - multimedia
Desarrollo android - 6 - multimedia
 
Hola mundo
Hola mundoHola mundo
Hola mundo
 
Intro. a Android Instituto Bosc de la Coma en Olot
Intro. a Android Instituto Bosc de la Coma en OlotIntro. a Android Instituto Bosc de la Coma en Olot
Intro. a Android Instituto Bosc de la Coma en Olot
 
BDJ Team_Oct2015_pg_BADT
BDJ Team_Oct2015_pg_BADTBDJ Team_Oct2015_pg_BADT
BDJ Team_Oct2015_pg_BADT
 
Er. Anand Resume
Er. Anand ResumeEr. Anand Resume
Er. Anand Resume
 
Interfaces increibles en Android
Interfaces increibles en AndroidInterfaces increibles en Android
Interfaces increibles en Android
 
Game store app(2)
Game store app(2)Game store app(2)
Game store app(2)
 
Desarrollo en Android: Conceptos Básicos
Desarrollo en Android: Conceptos BásicosDesarrollo en Android: Conceptos Básicos
Desarrollo en Android: Conceptos Básicos
 
Sincronización de BD SQLite con MySQL en Android
Sincronización de BD SQLite con MySQL en AndroidSincronización de BD SQLite con MySQL en Android
Sincronización de BD SQLite con MySQL en Android
 
Iniciación a Android
Iniciación a AndroidIniciación a Android
Iniciación a Android
 
Education and Management of Diabetics
Education and Management of DiabeticsEducation and Management of Diabetics
Education and Management of Diabetics
 
Diseño de interfaces móviles (UX y la arquitectura de software)
Diseño de interfaces móviles (UX y la arquitectura de software)Diseño de interfaces móviles (UX y la arquitectura de software)
Diseño de interfaces móviles (UX y la arquitectura de software)
 
Bases de Datos en Android y Desarrollo de Aplicaciones Móviles Multiplataforma
Bases de Datos en Android y Desarrollo de Aplicaciones Móviles MultiplataformaBases de Datos en Android y Desarrollo de Aplicaciones Móviles Multiplataforma
Bases de Datos en Android y Desarrollo de Aplicaciones Móviles Multiplataforma
 

Semelhante a Android service

Services I.pptx
Services I.pptxServices I.pptx
Services I.pptxRiziX3
 
Android service and gcm
Android service and gcmAndroid service and gcm
Android service and gcmRan Zeller
 
Android App Development - 08 Services
Android App Development - 08 ServicesAndroid App Development - 08 Services
Android App Development - 08 ServicesDiego Grancini
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentOwain Lewis
 
Andriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxAndriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxfaiz324545
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
OutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modulesOutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modulesKurt Vandevelde
 
Outsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modulesOutsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modulesProvidit
 
Service-oriented architecture (SOA) is a method of software development that ...
Service-oriented architecture (SOA) is a method of software development that ...Service-oriented architecture (SOA) is a method of software development that ...
Service-oriented architecture (SOA) is a method of software development that ...ssuser0d0f881
 
Displaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptxDisplaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptxsanaiftikhar23
 
6. Microservices architecture.pptx
6. Microservices architecture.pptx6. Microservices architecture.pptx
6. Microservices architecture.pptxdatapro2
 
Intro to Microservices Architecture
Intro to Microservices ArchitectureIntro to Microservices Architecture
Intro to Microservices ArchitecturePeter Nijem
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing MicroservicesNagarro
 

Semelhante a Android service (20)

Services I.pptx
Services I.pptxServices I.pptx
Services I.pptx
 
Aidl service
Aidl serviceAidl service
Aidl service
 
Android service and gcm
Android service and gcmAndroid service and gcm
Android service and gcm
 
Android App Development - 08 Services
Android App Development - 08 ServicesAndroid App Development - 08 Services
Android App Development - 08 Services
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Andriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxAndriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptx
 
Basics 4
Basics   4Basics   4
Basics 4
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
JINI Technology
JINI TechnologyJINI Technology
JINI Technology
 
OutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modulesOutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modules
 
Outsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modulesOutsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modules
 
Service-oriented architecture (SOA) is a method of software development that ...
Service-oriented architecture (SOA) is a method of software development that ...Service-oriented architecture (SOA) is a method of software development that ...
Service-oriented architecture (SOA) is a method of software development that ...
 
Displaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptxDisplaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptx
 
6. Microservices architecture.pptx
6. Microservices architecture.pptx6. Microservices architecture.pptx
6. Microservices architecture.pptx
 
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
 
Android101
Android101Android101
Android101
 
Grails services
Grails servicesGrails services
Grails services
 
Intro to Microservices Architecture
Intro to Microservices ArchitectureIntro to Microservices Architecture
Intro to Microservices Architecture
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
 

Mais de Krazy Koder (20)

2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xc
2310 b xc2310 b xc
2310 b xc
 
2310 b xb
2310 b xb2310 b xb
2310 b xb
 
2310 b 17
2310 b 172310 b 17
2310 b 17
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 14
2310 b 142310 b 14
2310 b 14
 
2310 b 13
2310 b 132310 b 13
2310 b 13
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
2310 b 10
2310 b 102310 b 10
2310 b 10
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 07
2310 b 072310 b 07
2310 b 07
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Android service

  • 2. Topics • What is a Service? • Service lifecycles • Permissions • Local services • Remote services
  • 3. What is a Service?
  • 4. When a Service Used? • Applications will need to run processes for a long time without any intervention from the user, or very rare interventions. • These background processes need to keep running even when the phone is being used for other activities / tasks.
  • 5. Two Types of Services • Local service > Not accessible from other applications > Runs in the same process of the application that starts it • Remote service > Accessible from other applications as well > Exposes to other applications through AIDL (Android Services Definition Language)
  • 6. Service and Notification • Service is a long lived component and does not implement any user interface of its own. > Typically a user interacts with a service through an activity that has a UI. • The service “notifies” the user in case of any need for user intervention. > Through the notification (such as status bar notification), the service can give a user interface for binding to the service or viewing the status of the service or any other similar interaction with the service.
  • 7. What Facilities Service Provide? • A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). > This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it. • A facility for an application to expose some of its functionality to other applications. > This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.
  • 8. Binding to a Service • Once a service has begun and is running in the background, activities can “bind” to the service. > In fact, if we want to bind to a service that has not started, calling to bind could initiate the service.
  • 10. Starting a Service • If someone calls Context.startService() then the system will retrieve the service (creating it and calling its onCreate() method if needed) and then call its onStartCommand(Intent, int, int) method with the arguments supplied by the client. • The service will at this point continue running until Context.stopService() or stopSelf() is called.
  • 11. Modes of Operations • For started services, there are two additional major modes of operation they can decide to run in, depending on the value they return from onStartCommand(): > START_STICKY is used for services that are explicitly started and stopped as needed, > START_NOT_STICKY or START_REDELIVER_INTENT are used for services that should only remain running while processing any commands sent to them.
  • 12. Getting a Connection to a Service • Clients can also use Context.bindService() to obtain a persistent connection to a service. > This likewise creates the service if it is not already running (calling onCreate() while doing so), but does not call onStartCommand(). • The client will receive the IBinder object that the service returns from its onBind(Intent) method, allowing the client to then make calls back to the service.
  • 14. Permissions • Global access to a service can be enforced when it is declared in its manifest's <service> tag. • By doing so, other applications will need to declare a corresponding <uses-permission> element in their own manifest to be able to start, stop, or bind to the service. • In addition, a service can protect individual IPC calls into it with permissions, by calling the checkCallingPermission(String) method before executing the implementation of that call.
  • 16. Local Service • One of the most common uses of a Service is as a secondary component running alongside other parts of an application, in the same process as the rest of the components. > All components of an .apk run in the same process unless explicitly stated otherwise, so this is a typical situation. • When used in this way, by assuming the components are in the same process, you can greatly simplify the interaction between them > Clients of the service can simply cast the IBinder they receive from it to a concrete class published by the service.
  • 18. Remote Messenger Service • If you need to be able to write a Service that can perform complicated communication with clients in remote processes (beyond simply the use of Context.startService to send commands to it), then you can use the Messenger class instead of writing full AIDL files.