Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android PackageManager.DONT_KILL_APP seems to not work

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?

like image 342
Alex Mensak Avatar asked Oct 30 '22 14:10

Alex Mensak


1 Answers

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);
like image 163
Vikas Avatar answered Nov 08 '22 08:11

Vikas