Skip to content

Instantly share code, notes, and snippets.

View HectorRicardo's full-sized avatar

Hector Ricardo HectorRicardo

  • Google
  • Irvine, CA
View GitHub Profile
@HectorRicardo
HectorRicardo / jni.md
Last active June 3, 2022 05:27
JNI Guide

Android Services

A service is an application component that performs work in the background, without a visible user-interface. For example, a service could be an audio player playing music while the user is in another app or has the device locked. While the current song is playing, the service might also be retrieving the next song from the network.

A service runs in the main thread of its hosting app process; the service does not create its own thread and does not run in a separate process unless you specify otherwise. You should run any blocking operations on a separate thread within the service to avoid Application Not Responding (ANR) errors.

As with other application components, the service class must be a top-level class (i.e. not an inner class of another class) and be declared in the manifest. (In the manifest) you can declare such class as:

  • private: only application components within your app can use the service
  • public: application components from outside your app can use the service as well