try { ComponentName componentName = new ComponentName(getPackageName(), YourActivity.class.getName()); PackageManager packageManager = getApplicationContext().getPackageManager(); if (licenseState == LICENSE_VALID) { if (packageManager.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } } else if (licenseState == LICENSE_INVALID) { packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } } catch (Exception ex) { // Be sure to trap any and all potential issues with the above code. // It's not critical that it succeeds. Log.d(TAG, "Disabling component failed", ex); }