Android - creating custom launcher

Well, firstly you need to listen to the android.intent.category.HOME intent. Here are some links with full source code which you can have a look at:

  • Old launcher source code
  • New launcher source code

Or take a look at launcher plus.


I saw this thread a while ago, before creating my own launcher.
Here are some crucial things I learned:


Declaring your app to be a launcher

David already mentioned the piece of code that determines your app as a launcher:

<category android:name="android.intent.category.HOME" />

Add this as an intent-filter to the activity your launcher will use for the home screen (in AndroidManifest.xml).

Launcher Issues

As a launcher will run all the time, you need to understand the activity livecycle to prevent issues (like this one).

If you want users (and yourself) to be able to constantly user the app (that's what you usually do with launchers), make sure it never crashes. In the case of a crash users will be taken back to the devices default launcher or other installed ones.

In short: Launchers are expected to be reliable.

Common launcher functions (users usually expect those)

1) A list of apps / appdrawer

From which all apps can be launched or modified. You can use packageManager to list the apps.

As generating such a list may take a while, I suggest you to do it asynchronously and save the list somewhere to speed everything up (which also is expected from launchers ^^)

2) Some settings to change the launcher

I had some users stuck in my launcher before implementing those ^^

You can open the devices launcher settings like this (in Kotlin):

// working in APIs newer than Lollipop
val callHomeSettingIntent = Intent(Settings.ACTION_HOME_SETTINGS)
startActivity(callHomeSettingIntent)

Bonus) An in-app tutorial

This may be useful if you have some features in your app that are not trivial, ways of launching apps that users don't know from other apps.

It also gets you way less messages from users asking how to interact with your software.


Resources:

  • The GitHub of the minimal launcher I created may be helpful: finnmglas/Launcher