Hide and Unhide Application in HomeScreen Android

For Hide application icon:

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

For Unhide Application:

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Known Issue:

After hide application your Activity will destroyed. So trying to start my main activity but its giving me ActivityNotFoundException.

Solution:

After hide you MainActivity once you hide it the activity will not be found it’s destroy so you need to create same another activity like mainActivity2 and you need to store boolean value to sharerdprefrence that whether icon is hiddne then u need to open mainActivity2 else MainActivity

Advertisements