Android app shortcuts and class names

I recently learned the hard way that refactoring your old code to be more consistent with how you write code now as opposed to how you wrote it a year ago can be dangerous. Things like class names may seem like a completely internal mechanism and is in most cases, but the rule for that changes the moment you place one into the AndroidManifest.xml.

If you change the name of your launcher class in the AndroidManifest, it affect more than just how the Android OS launches your app. It affects everyone that has ever created a shortcut on the Home screen for your app. Shortcuts on the Home screen internally have a link to your Activity class name used to launch your app so that it won’t have to query the package manager to figure out your launcher Activity every time you tap it, unlike the App Launcher. If you change the name of it and release it as an update, all the previously created shortcuts will now be broken and will need to be recreated in order to function again. If you still want or need to change the name, create a descendant class with the old name extending the class with the new name and place that descendant class as an exported Activity in your AndroidManifest file so that people can still use their old shortcuts.

Plan your externally facing class names carefully. You will be stuck with them for the life of your app. Although, you could do some interesting things if you changed the name of your launcher and then created another Activity based on the old name to show something completely different instead after an update. I wonder if there’s a use case for something like that.

Leave a Reply

Your email address will not be published. Required fields are marked *