How to have Android Service communicate with Activity
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
An Android Activity and a Service often need to exchange state, progress, or commands, but they live on different lifecycle tracks. The right communication approach depends mostly on whether the activity needs to call the service directly, receive updates from it, or communicate across process boundaries.
For same-app, same-process communication, a bound service is usually the cleanest option. For looser coupling or background notifications, callbacks, broadcasts, or observable shared state can work better.
Bound Service for Direct Communication
A bound service lets the activity call methods on the service directly through a binder. This is the most straightforward pattern when the activity is actively on screen and needs live access to service state.
Service example in Kotlin:
Activity binding to the service:
This pattern is simple and efficient when both components are in the same process.
Sending Updates from Service Back to Activity
Direct method calls from activity to service are only half the story. Often the service needs to push updates such as progress or status changes back to the activity.
A callback interface is one option:
The service can keep a nullable listener reference and notify it when work changes. But a callback must be managed carefully to avoid leaking the activity after configuration changes.
Another option is to expose observable state from a repository or other shared component that both the service and activity use. That reduces direct lifecycle coupling, though it adds architectural complexity.
Messenger or IPC Cases
If communication crosses processes, a local binder is not enough. In that case Android provides patterns such as:
- '
Messengerfor message-based IPC' - '
AIDLfor more formal cross-process interfaces'
These are more advanced and usually unnecessary unless the service is designed for inter-process communication.
For many ordinary app cases, the question is not "how do I send messages across processes." It is "how do I avoid overcomplicating a same-process app." The answer is usually to stay with a bound service or a shared observable state holder.
Choosing the Right Pattern
Use a bound service when:
- the activity needs direct access to service methods
- both components live in the same process
- the UI is actively interacting with the long-running component
Use looser event-style communication when:
- multiple screens may observe the same service state
- the activity may come and go while work continues
- you want less direct coupling
There is no one universal pattern. The best choice depends on whether the communication is command-driven, state-driven, or cross-process.
Common Pitfalls
- Forgetting to unbind the service can leak the activity.
- Trying to update the UI directly from a background thread in the service can crash or behave unpredictably.
- Keeping a strong callback reference to a dead activity can create lifecycle bugs after rotation.
- Using IPC-heavy patterns for a same-process app usually adds complexity without benefit.
Summary
- A bound service is usually the simplest way for an activity to communicate with a service in the same app.
- The activity can call service methods through a binder after binding.
- Service-to-activity updates need lifecycle-aware callbacks or a shared observable state approach.
- Use
MessengerorAIDLonly when real cross-process communication is required. - Pick the communication pattern based on lifecycle needs, not just on what Android technically allows.
Related reading
- How to have multiple cache manager configuration in spring cache java
- How to hot-reload properties in Java EE and Spring Boot?
- How to ignore SSL certificate errors in Apache HttpClient 4.0
- How to implement a distributed system using multiple ports with Java CORBA?
- How to have stored properties in Swift, the same way I had on Objective-C?
- How to have stored properties in Swift, the same way I had on Objective-C?
- How to implement a Kafka consumer in a Spring MVC web app (using Spring Boot)
- How to implement a microservice Event Driven architecture with Spring Cloud Stream Kafka and Database per service

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.