Activity-Alias ​​is removed on the application update


I have implemented two activity-alias that the user should be able to enable or disable in runtime.


        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>

I do not want them to be enabled in the beginning, to not clutter up the app-screen of the users device. But in runtime, the user should be able to enable the alias. I do this via the PackageManager:

PackageManager pm  = getApplicationContext().getPackageManager();
ComponentName componentName = new ComponentName(context, ".ui.alias.open_location");

This works like charm in the beginning, but the alias gets disabled again, when an update of my app is installed. How can I prevent the system from overwriting the enabled state by the manifest? I don't want the user to floot with Launcher in the beginning and I don't want the user to recreate all alias shortcuts after an update.

I think I would need something similar to PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER, but only for enabled state.


All the configurations of the enabled or disabled components are saved in this path of the device (0 is for the first user of the device):


The format of the XML is something like this (you can pull the file only from a rooted device):

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
    <pkg name="com.example.myapplication">
            <item name="com.example.myapplication.ActivityAlias" />
    <preferred-activities />
    <persistent-preferred-activities />
    <crossProfile-intent-filters />

When you update the app the enabled or disabled components remain the same, even if you clear the data of the app.

The only case in which this setting is lost is when the package name or the name of the component change.

I think your problem is due to the changing of the component name (maybe some strange configuration of ProGuard/DexGuard), since you can't upload on the play store an update with a different package name.

You can try to decompile the APK and verify if the name of the component is the same in both the app.