Android Kiosk Mode - Allow Exit

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);
homeIntent.addCategory(Intent.CATEGORY_HOME);
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
        homeIntent.setClassName(info.activityInfo.packageName,
                       info.activityInfo.name);
        break;
    }
}
// Launch the default HOME screen
startActivity(homeIntent);
finish();

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.