Android Basics – Learn how to create a Started Service using an IntentService

In the last Article you learnt about Android Services and the difference between a bound and a started service. In this Article you will learn how to call the IntentService you created earlier.

To create a started service you need to extend the IntentService class.

public class SampleService extends IntentService

Let’s take a simple example to illustrate how this works.

In the onHandleIntent method you will add a Log.

protected void onHandleIntent(Intent intent) {
    Log.v(TAG, "In onHandleIntent. Message will be printed after 10sec");
    if (intent != null) {
        synchronized (this){
            try {
            } catch (InterruptedException e) {
            Log.v(TAG, "Service started");

To call this service you will add a button to the content_main.xml file

    android:text="Start Service"

On click of this button an explicit intent will be called.

if(v.getId() =={
    Log.v(TAG, "Service Button Clicked");

    Intent intent = new Intent(this, SampleService.class);

View the complete source code here.

Author: Ankur

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: