AppLaunchChecker – a first quick analysis

With the release of the Android Support Library revision 23.3.0, a new utility class has been introduced: AppLaunchChecker.

Its aim is very simple:

To help track how your app has been launched by the user in the past. This can be useful if you want to confirm that a user has launched your app through its front door activity from their launcher/home screen, rather than just if the app has been opened in the past in order to view a link, open a document or perform some other service for other apps on the device.

According to the change log, it is sufficient to call hasStartedFromLauncher() method to know if the user has launched the application from the home screen.

So, let’s try to to add the following code in typical Hello World application:

protected void onResume() {
    if (AppLaunchChecker.hasStartedFromLauncher(this)) {
        Toast.makeText(this, "Started from launcher", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "NOT started from launcher", Toast.LENGTH_SHORT).show();

Launching it from the home screen, we would expect to see “Started from launcher” displayed by a Toast, instead “NOT started from launcher” is shown.

Looking into AppLaunchChecker source code, we can notice two things: first, there’s another public static method available called onActivityCreate, second, the overall logic is simply based on SharedPreferences.

In fact, from the comment we know that:

To track this state properly you must call onActivityCreate(Activity) in your launcher activity’s onCreate(Bundle) method.

This method is responsible to set to true a boolean key named startedFromLauncher in a preference file called Of course if the key already exists and it is set to true or the Activity’s launching intent is null nothing is done.

So let’s give it a try:

protected void onCreate(Bundle savedInstanceState) {


Building again the application and launching it from the home screen, we now get the “Started from launcher” Toast.

Thus, this new utility class is nothing more than the typical “workaround” based on SharedPreferences already used by many developers: when the launcher Activity is created, a boolean shared preference is set to true, then later in the lifecycle of the application, calling hasStartedFromLauncher, we simply get its value.

Important: it’s not possible using Android Support Library public methods to set back the preference to false. In fact, reading carefully the documentation, the key parts are:

… your app has been launched by the user in the past.

… if this app has been started by the user from the launcher at least once.

That means this utility class is only useful to know if the application has been launched from the home screen at least once in the past but not every time it’s launched: in fact, after the fist time, you will get always true from hasStartedFromLauncher.

Leave a Reply

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