My app is disappear in the recent apps after dynamic changing the app Icon with Android 9.0

303 Views Asked by At

I use activity-alias to dynamically change the icon of my application, resulting in my application disappear in the recent apps.

Manifest

<activity-alias
    android:enabled="false"
    android:icon="@mipmap/ic_launcher_11"
    android:label="@string/app_name"
    android:name=".ui.launcher_d_eleven"
    android:targetActivity=".ui.SplashActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity-alias>
private void enableComponent(PackageManager pm, String launcher) {
    ComponentName newComponent = new ComponentName(this, launcher);
    pm.setComponentEnabledSetting(newComponent,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}


private void disableComponent(PackageManager pm, String launcherAlias) {
    LoggerUtil.e("zkx disable Launcher = " + launcherAlias);
    ComponentName deComponent = new ComponentName(this, launcherAlias);
    pm.setComponentEnabledSetting(deComponent,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
}
1

There are 1 best solutions below

0
On

Hitting it a bit late but I got a solution for this, you need to add a default alias pointing to the MainActivity without changing the icon and remove the Launcher property in the Main Activity's intent-filter manifest. So your MainActivity would look like this

<activity
        android:name=".MainActivity"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>

And add a default alias that looks like this

<activity-alias
        android:name=".Default"
        targetActivity = ".MainActivity"
        enabled = true>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

And then when you don't enable/disable your MainActivity, you disable the alias and substitute it with another alias That's what worked for me