What to know about Android service?

| Tuesday, October 2, 2012
By Andy Gather


If you are an amateur android developer, then you could have heard about the service class of it. Today I'm going to tell you something engaging about it. I will try to offer you the basic information about service classes in the following paragraphs. So let's go!

General Overview

Fundamentally it's an application component which performs 2 first actions. Either it represents the need of an application to perform a longer running operation (while not interacting with user), or it supplies functionality for other applications to be used. Every class contains a corresponding stipulation in its package Androidmanifest.xml. The point to be noted here is that they run in the main thread of application's process. For example, if your service is going to play an MP3 track, then it should spawn its own thread for doing so.

What is service class?

Now before developing something utilising the class, you should obviously know that what it is and what it is not. First let us learn what it is not, because most mess ups happen just because of not grasping that. Given below are the solutions to this question:

- It is not a separate process.

-It doesn't run its separate process unless it is mentioned in the source code.

-It runs in the identical process as the application.

- It is not a thread. It doesn't do the work of main thread (for smoother running of app without mistakes).

Now let us find out what it is:

- It is a facility of the app to tell the system that it wants to do something in background. This corresponds to Context.startservice (), and tells the system to run a certain process in background until somebody clearly stops it.

- It's also a facility of a program which allows the exposure of some of its features to other ones. This function calls Context.bindservice () and tells the system to build an established connection between the applications for interacting with one another.

When a class is created for any of the above given reasons, the system instantiates its 'oncreate () ' and all of the other significant callbacks on the key thread. After that, service itself performs the mandatory actions (i.e. Creating a new thread for doing its work). Always remember that this class itself is pretty customizable, so you can make it as simple as you would like or as hard as you want according to your needs.




About the Author:



0 comments:

Post a Comment