Disable Unusable Activities

If you examine the manifest file for the AOSP Email app, you will notice something interesting: some of the activities ship disabled.

For example, the MessageCompose activity — which is responsible for handling ACTION_SEND and ACTION_SENDTO requests — has android:enabled="false" on its <activity> element.

The reason is that this activity is useless until the user has gone in and set up one or more email accounts. The Email app, therefore, leaves this activity disabled by default, enabling it only after the user has set up an account.

This way, Email does not show up unnecessarily in choosers for ACTION_SEND and ACTION_SENDTO. While the Email application has the code to handle those requests, it does not always have the configuration to handle those requests. By disabling the component, the Email app ensures that the user will only be able to choose the Email app when the Email app can actually fulfill the request.

If your application supports common implicit Intent actions like ACTION_VIEW, ACTION_SEND, and so on, you should consider following in Email’s footsteps. If your app can always handle those actions, having a regular activity is fine. If, however, your app requires user setup before it can handle those actions, disable the activity at the outset, enabling it via PackageManager and setComponentEnabledSetting() when the activity becomes applicable.


Need Android app development training for your team? Mark Murphy has trained hundreds! Learn more!