Android SDK: Add application to the autostart

Add your Android application to the autostart

To add an Android application to the device’s autostart is actually pretty easy. But if some minor but important settings are wrong the autostart function doesn’t work. Here comes a fully functional example which opens your Android application after the device has finished its booting sequence.

  • Create a new Android application in Eclipse called „OnBootCompletedExample“. The namespace is on.boot.completed.
  • Leave the main Activity as is:

    import android.os.Bundle;
    public class OnBootCompletedExampleActivity extends Activity {
    	/** Called when the activity is first created. */
    	public void onCreate(Bundle savedInstanceState) {
  • Create a new class called which extends BroadcastReceiver:

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.util.Log;
    public class Autostart extends BroadcastReceiver {
    	 * Listens for Android's BOOT_COMPLETED broadcast and then executes
    	 * the onReceive() method.
    	public void onReceive(Context context, Intent arg1) {
    		Log.i("Autostart", "BOOT_COMPLETED broadcast received. Executing following code:");
    		Intent intent = new Intent(context, StarterService.class);

    In the AndroidManifest.xml file we are going to add this class as a receiver. This class will listen to the broadcast call the Android OS sends after the boot sequence has finished (meaning after the phone started up).

  • Create another class called which will extend Service:

    import android.content.Intent;
    import android.os.IBinder;
    import android.util.Log;
    import android.widget.Toast;
    public class StarterService extends Service {
    	private static final String TAG = "MyService";
    	public IBinder onBind(Intent intent) {
    		return null;
    	public void onDestroy() {
    		Toast.makeText(this, "My Service stopped", Toast.LENGTH_LONG).show();
    		Log.d(TAG, "onDestroy");
    	 * The started service opens the Activity.
    	public void onStart(Intent intent, int startid) {
    		Intent intents = new Intent(getBaseContext(), OnBootCompletedExampleActivity.class);
    		Toast.makeText(this, "My Service started", Toast.LENGTH_LONG).show();
    		Log.d(TAG, "onStart");

    When the class Autostart receives the BOOT_COMPLETED broadcast from Android OS it will start the StarterService which then starts the Android Activity „OnBootCompletedExampleActivity“.

  • And finally we update the AndroidManifest.xml with the changes we need to do in order for the application to work how we want:


    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android=""
        android:versionName="1.0" >
            android:targetSdkVersion="7" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
            android:label="@string/app_name" >
                android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
            <receiver android:name="on.boot.completed.Autostart" >
                    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                android:exported="true" />

    A few notes about AndroidManifest.xml:

    • It’s very important to add
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

      before the <application> tag.

    • If the app is installed on the SD Card the autostart will not work! That’s why it’s important that we add

      after package=“on.boot.completed“

    • Also add
      <action android:name="android.intent.action.QUICKBOOT_POWERON" />

      in addition to

      <action android:name="android.intent.action.BOOT_COMPLETED" />

      to the receiver. Some HTC devices won’t catch the BOOT_COMPLETED broadcast.

That’s all. Now build and run your app. After it has been started turn off your phone and turn it back on and the app should start automatically after the device has booted up.

Here you can download the working Android project:

About Dominik
Currently working as an Android/iOS developer for Cineman, Switzerland. Owner of and


One Response to “Android SDK: Add application to the autostart”
  1. Ravi sagt:

    Awesome website. Thanks for your code. it mean lot to u.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.