Android Start Service on Boot Automatically

Android Start Service on BootAndroid Start Service on Boot Automatically (Autostart Android Application)

Here we will learn about Android Start Service on Boot Automatically (Autostart Android Application). That means we will learn the simplest way to start an Android service or an application at device boot up. It is very simple. First we will register an Android event called ‘android.intent.action.BOOT_COMPLETED’. Then we will capture this event when boot up completed and start our service. Then we will start our app from the service.

Step 1:

First we need an Android  service to started at device boot up. Your service looks like below. If you are new to Android service then i recommend you to learn about simple Android service with example. I have written a very nice article on Android Services. Click here to read.

 Step 2:

Now we need a class which extends from BroadcastReceiver class. In this class there is a method called onReceive() that will be called when the boot event is completed. From the onReceive() method we will start the Android service which we have just created in above step 1.

 Step 3:

Now We need do 3 things in Android Manifest file.

1. Add the permission in Manifest file to capture the boot complete event.

2. Register your BroadcastReciever class in Manifest file to receive the boot complete event.

3. Register your Service class in Manifest File which we need to start when boot completed.

4. Your Manifest file looks like below.

Note: The above Manifest file is just an example for Android Start Service on Boot Automatically.

 Step 4: Start Android Application at Device boot up.

Now if you want to start (launch) an Android activity at device boot, then start the activity from the service instead of start it from the receiver.

Tips:

  • The onReceive() function in the receiver class expire with in 8 seconds, if you will do any time consuming task or waiting more than 8 seconds in onReceive() function, then your application will crash with ANR. So better to start a service and from the service you can do a time consuming task.

I hope this small tutorial on ‘Android Start Service on Boot Automatically‘ will help you at it’s best.

 

Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon

Connect

5 Responses to Android Start Service on Boot Automatically

  1. Hemant katariya says:

    Please provide me the link for full code,
    Bcz it’s force close

  2. Muhammad says:

    Nice tutorial, work fine

  3. pradeep says:

    Really helpfull.Cool tutorial..
    Thank you very much..:)

  4. Imran says:

    sir i am doing exactly same but background service run multiple times…

    i want to run only once after boot complete….

    Samsung glaxy S3(jelly bean 4.1.2)

Leave a Reply

Your email address will not be published. Required fields are marked *


+ five = 11

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">