Booting into your own application on Android

Published on June 3, 2011

Archived Notice

This article has been archived and may contain broken links, photos and out-of-date information. If you have any questions, please Contact Us.

Here's another favorite for fixed-point Android users.  How do we skip the home screen and go directly into our own custom application on system start?  Once again, this is an easy change to make, and we really don't even have to mess with the framework code to make it work. If you have any Android development experience, you already know how intents and intent filters work.  Intents are Android's way of calling up new activities, whether it's a new screen within your own app or some other app that does something we need -- say, send a text message, even though Joe User might have one of many default SMS apps installed on his device.  The point is, you don't need to know the name of the app you want to start as long as you know what, generally, you want it to do. Intent filters are Android's way of resolving the slightly vague "I want to do this, and I don't care what app does it" intents.  Say you wrote a special new browser app -- you could specify a BROWSABLE category filter in the AndroidManifest.xml file.  That way, when your user opens a URL, they can be given the option to use your browser app instead of the default. Let's get to the point.  The 'home screen' you're used to seeing on your Android phone is an app just like any of the others you've installed.  When the system server is done initializing everything and knows it's ready to start, it sends out an intent that tells Android to start the home activity.  For our Gingerbread build, the default one is Launcher2. Look in the manifest file and you'll see this block of code (or something that looks remarkably similar):

<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.HOME" />
   <category android:name="android.intent.category.DEFAULT" />
   <category android:name="android.intent.category.MONKEY"/>
</intent-filter>
This is the intent filter for Launcher2's main activity. The key here is the category filter android.intent.category.HOME.  Android looks for application manifests that have this filter registered when it starts up -- this tells it that this activity is a home activity that it can boot into.  So, copy that line into the intent filter for your own app's main activity in the manifest file.  Reinstall your app. If you did it correctly, on your next startup you should see the dialog box that lets you choose between Launcher2 and the application you just modified.  Success! At this point, the dialog should give you the option to set this app as the default home application -- or, if you prefer, you can simply remove Launcher2 from your build altogether by removing Launcher2.apk from your device's system/apps/ folder.