activity-alias : Manage app upgrades, Two Launcher Icons

Alias for an activity which is specified with targetActivity attribute. Target activity should be in same application to that of alias. Target activity has to be declared before alias in manifest file. activity-alias can have its own attributes as we define for activity in manifest. It represents the target activity as an independent entity.

Apart from target Activity attribute, activity-alias attributes are a subset of activity attributes. If alias defines its own attributes, target activity attributes will not be applied. Though for attributes which are declared in target activity and not declared in alias, they will be applied to alias as well.

Alias and target Activity can have different intent-filter and each will behave as different entity even though name attribute of alias does not exist.

Use of activity-alias
1. For application upgrade, package structure has changed. can be used to persist applications shortcuts and launcher icons.

2. We need two launcher activities with different icon in our application to take user to different usability/functionality view.

3. If there is minor functionality change between two screen, its better to use alias and use targetActivity rather than rewriting a complete class for alias activity.

Sample activity-alias application




Let’s define layout for target activity, modify your /res/layout/activity_main.xml as below where we will use text view to show launch info.

In AndroidManifest.xml, we will define one launcher component MainActivity as usual. We will define alias AliasActiity for which MainActivity will act as targetActivity. We will set different icon and label for these to differentiate. Target activity must be declared before alias inside application tag.

Defining activity-alias is saving us overhead of creating another class. We just defined targetActivity attribute and will act host for our alias. In, we can retrieve component from the intent with which it was started and you will observe different component names. Based upon these, you can modify your functionality and views for respective launch.

Run your application you will get two icons on launcher for main activity and activity-alias.

Similarly, we can handle for code package upgrade. Suppose in previous version of application our launcher component was "com.androidsrc.old.MainActivity" and now it has been moved to "". We can use activity-alias for this case. You can delete previous class file without any problem. Just in your manifest, you will create alias which will have target Activity to new class.

Kudos, we just managed to delete old source files and still preserved application shourtcuts on launcher.

You may also like...