Working with Services Android

Trying to wrap your head around Activities, Intents, Intent Filters, and the lot when you start with Android development can be daunting. We have tried to distill everything you need to know to start writing Android applications with multiple Activity classes, but we’d be remiss if we didn’t mention that there’s a lot more here, much of which is discussed throughout the book using practical examples. However, we need to give you a “heads up” about some of these topics now because we talk about these concepts very soon when we cover configuring the Android Manifest file for your application in the next chapter.

One application component is the service. An Android Service is basically an Activity without a user interface. It can run as a background process or act much like a web service does, processing requests from third parties. You can use Intents and Activities to launch services using the startService() and bindService() methods. Any Services exposed by an Android application must be registered in the Android Manifest file. You can use services for different purposes. Generally, you use a service when no input is required from the user. Here are some circumstances in which you might want to implement or use an Android service:

  • A weather, email, or social network app might implement a service to routinely check for updates. (Note: There are other implementations for polling, but this is a common use of services.)
  • A photo or media app that keeps its data in sync online might implement a service to package and upload new content in the background when the device is idle.
  • A video-editing app might offload heavy processing to a queue on its service in order to avoid affecting overall system performance for non-essential tasks.
  • A news application might implement a service to “pre-load” content by downloading news stories in advance of when the user launches the application, to improve performance.

A good rule of thumb is that if the task requires the use of a worker thread and might affect application responsiveness and performance, consider implementing a service to handle the task outside the main application lifecycle.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Android Topics