Services in Android

Overview

  • An application component that can perform long running task in the background.
  • Once started a service might run in the background even if the user starts using other applications.
  • A service doesn't have an interface
  • A service runs in the main thread by default. A service does not create its own thread and do not run in a separate thread unless you specify the service to run on a separate thread in order to avoid ANR (Application Not Responding) error.
  • A service has it's own life cycle.

Types of Services

Foreground Services

  • It's noticeable to the user.
  • Foreground service must display a notification.
  • Foreground service continues running, even when a user isn't interacting with the application that is associated with the service.
  • You can use WorkManager to control Foreground service.

Background Services

  • It runs in the background and it isn't noticeable to the user.

Bound Services

  • Bound services are the ones that is attached to an application components. 

Lifecycle of Services


Lifecycle of Services in Android


References




Android Logo


Comments

Popular posts from this blog

SSLSocketFactory in Android

Architecture Components in Android

DataBinding in Android