Home » Android » Android Kiosk Mode – Allow Exit

Android Kiosk Mode – Allow Exit

Posted by: admin June 15, 2020 Leave a comment


I am writing Android application for kiosk mode. I am using this tutorial to create kiosk mode: http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/

However, in the tutorial, the user still can click on home and then the application back after 2 seconds.

So, I did a bit of modification to disable the home button by making my application as a home. I did it by put this in my manifest:

<activity android:name=".MainActivity"
        <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.LAUNCHER" />

Everything work well. But when the user try to exit (ie. user login as administrator), my application is back again. I suspect because I set it as HOME.

My question is, how to allow my app to Exit. Is it possible to go back to actual home when my app exit? If not, is there a better way to tackle this home problem (ie. disable home button and not actually set it as home)?

How to&Answers:

You have multiple HOME screens installed (the default one provided by the device manufacturer, and your app). The user must have chosen that your app should be the default HOME screen (this usually happens at boot time). What you now want to do is to remove this “preferred” setting so that the user can choose a different “default” HOME screen (ie: the manufacturer’s app). Do that like this:

PackageManager pm = getPackageManager();
pm.clearPackagePreferredActivities ("your.package.name");

and then finish() your MainActivity.

EDIT: Alternative solution

As an alternative solution, when you want to “exit” your app, you just launch the default HOME screen instead. To do this, you need to either know the package and class name of the default HOME screen and hardcode that, or you can scan for that info using PackageManager like this:

PackageManager pm = getPackageManager();
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
List<ResolveInfo> infoList = pm.queryIntentActivities(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);
// Scan the list to find the first match that isn't my own app
for (ResolveInfo info : infoList) {
    if (!"my.package.name".equals(info.activityInfo.packageName)) {
        // This is the first match that isn't my package, so copy the
        //  package and class names into to the HOME Intent
// Launch the default HOME screen

In this case, your app is still set as the default HOME screen, so if the user presses the HOME key again, your app will be started. But the user can then “exit” your app to return again to the original HOME screen.


You can use the device owner capabilities introduced in Android 5.0 to fully manage an Android device and use it as a kiosk. Among other things this allows you to prevent the user from exiting the app by tapping the home button.

The simplest way to set up a device owner kiosk is to use the Android Management API and configure a kiosk policy.