In my recent project Im hiding app icon from launcher by using COMPONENT_ENABLED_STATE_DISABLED flag. Here you can see code:
PackageManager packageManager = SettingsActivity.this.getPackageManager();
ComponentName componentName = new ComponentName(SettingsActivity.this, MainScreen.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
This is launched when user press checkBox. But some how every time after like 10-15 seconds the app sudently stop. Whith no error or message.
I dont understand it because I have used DONT_KILL_APP flag..
Any suggestions?
First get your apps package name:
String packageName = activity.getPackageName();
Then set clsDefault from the name you must have defined in your in your Manifest file.
<activity-alias
android:name=".HomeScreen-Default"...>
public static String clsDefault = packageName + ".HomeScreen-Default";
Then use this to set the icon.
activity.getPackageManager().setComponentEnabledSetting(new ComponentName(packageName, clsDefault ),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With