Architecture of Mobile Applications
1. Definition and Importance
1.13. Services
3. Services
Definition
A Service is a background process that runs independently of the user interface. Services do not provide a UI but perform long-running operations. A Service is a background process that performs long-running operations without a user interface. It's like a worker that runs behind the scenes. Services are used for tasks like downloading files, playing music, or syncing data.
Key Characteristics
- Services run in the background without user interaction.
- They can perform operations like downloading files, playing music, or handling network requests.
- Services can run indefinitely or for a limited time.
Types of Services
- Foreground Services
Run actively and show a notification. Perform operations that are noticeable to the user (e.g., playing music). They must display a notification to the user.
Example: Music player service.
- Background Services
o Run without user interaction. Perform operations that are not directly noticeable to the user (e.g., downloading a file in the background). Android has restrictions on background services to conserve battery.
o Example: Data synchronization.
- Bound Services
Allows other components (activities/fragments) to bind and interact with it. Allow other components (Activities or other Services) to bind to them and interact with them. This is useful for client-server architectures within the app.
o Example: Communicating with a remote server.