After the app icon and app name changed programatically, then after minimizing the app the application not found in background
408
Create such config in Manifest.xml
<activity android:name="package.name.MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/CustomTheme"
android:launchMode="singleTask">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias android:label="@string/app_name_default"
android:icon="@drawable/icon_default"
android:name=".MainActivity-Default"
android:enabled="true"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name_flavor_one"
android:icon="@drawable/icon_flavor_one"
android:name=".MainActivity-Flavor-One"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
Now you can switch between those two aliases, therefore we will change app icon or/and name. To switch from Default to Flavor-One use this code.
getPackageManager().setComponentEnabledSetting(
new ComponentName("package.name", "package.name.MainActivity-Flavor-One"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
getPackageManager().setComponentEnabledSetting(
new ComponentName("package.name", "package.name.MainActivity-Default"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Keep in mind that you have to track that only one alias will be enabled at a time
Author by
Tester12
Updated on December 19, 2022Comments
-
Tester12 over 1 year
In android kotlin, I had changed the app icon and app name using activity alias concept. But after switch the icons and app name. When the app is minimized the app is not found in my background. Attached video link for issue reference:https://drive.google.com/file/d/1V59pBDjhC6kvK5uvnRH3Miqd291pbN2g/view?usp=sharing
My Mainactivity.kt and android.xml code below:
packageManager.setComponentEnabledSetting(ComponentName("com.example.batpoc","com.example.batpoc.MainActivityOneLaunch"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP) packageManager.setComponentEnabledSetting(ComponentName("com.example.batpoc","com.example.batpoc.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP) <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.batpoc"> <!-- io.flutter.app.FlutterApplication is an android.app.Application that calls FlutterMain.startInitialization(this); in its onCreate method. In most cases you can leave this as-is, but you if you want to provide additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> <application android:name="io.flutter.app.FlutterApplication" android:label="batpoc" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity-alias android:name=".MainActivityOneLaunch" android:enabled="false" android:roundIcon="@mipmap/th" android:icon="@mipmap/th" android:label="One Launch" android:targetActivity=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity-alias> </application>
Please guide.Thanks in advance.