1 min read

Dynamic App Icons on Android using activity-alias

Ever wonder how apps like Discord or Twitter let users change their app icon? It’s not magic—it’s an Android trick using activity-alias in the manifest file! By toggling between the main activity and an alias with different icons, you can dynamically switch the app icon during runtime.
Dynamic App Icons on Android using activity-alias
Example of Discord Nitro, Reddit Premium, and Twitter Blue paid features to change app icons on Android

Have you seen an app that can change the app icon by itself? Apps that offer in-app purchases sometimes do this. For example, Discord with its Discord Nitro, Twitter with its Twitter Blue, or Reddit with its Reddit Premium. They allow the users to change how the app icon looks. For me personally, that kind of feature makes me think "What kind of magic is this?" Because we know the source of the app icon is coming from the manifest. So do they dynamically change the manifest file? Is that possible? Well, the answer is no, but they are using activity-alias for this magic trick. Let's take a look by checking how usually app icons are set.

Typically, app icons are set in the AndroidManifest.xml using attributes like android:icon and android:roundIcon. But for apps that offer users the ability to change their icons dynamically, developers employ the use of activity-alias in the manifest file.

In this example, two entries point to the same YourActivity class. The first acts as the main launcher icon, while the second serves as an alias with a different icon. When the app is installed, the icon of the main activity is set. Then, we can toggle the activity alias, to switch the icon to that of the alias on the runtime using PackageManager class.

The snippet above demonstrates the use of the setComponentEnabledSetting method of the PackageManager class. By passing the component names of both the activity-alias and the main activity, we can enable the activity-alias while disabling the main activity. This action effectively changes the app icon.

Now, here's the deal, we're all in this Android development game together. So, why not share the love? Drop this post to your dev buddies, start a chat, and let's make sure this icon-changing magic becomes common in our community. Can't wait to see more apps rocking this trick! 🚀