How to to run a function in background even after the app is closed?

Services are one of four fundamental app components of Android (other three being Activities, Broadcast Receivers and Content Providers). They can perform long running tasks in background, even after the application is closed, for an indefinite period of time.
Some simple use cases of services:

  • Playing music in background
  • Fetching data from a remote server.
  • Downloading files from the internet.

Like Vishwas mentioned, this implementation of services doesn’t directly let app developers to use services currently. They still need to depend on extension devs to write extensions for their specific use case. For example, there could be an extension for playing music in background or a file downloader extension that works even when the app is closed.

And talking about the extension for running procedures in background, I don’t really think it is a good idea. (I’ve changed my mind! :wink: :face_with_hand_over_mouth:) I’d rather there should be inbuilt blocks that would let users harness all the powers of services. Maybe in near future, this might be possible.

11 Likes