Design Tips

You can either test that an activity matches the intent, which you can do before starting the activity, or catch an exception if starting the activity fails. Both approaches are descibed in the blog posting Can I use this Intent?.

To test whether an intent can be resolved, your code can query the package manager. The blog post provides an example in the isIntentAvailable() helper method. You can perform this test when initializing the user interface. For instance, you could disable the user control that initiates the Intent object, or display a message to the user that lets them go to a location, such as the Market, to download its application. In this way, your code can start the activity (using either startActivity() or startActivityForResult()) only if the intent has tested to resolve to an activity that is actually present.

0 0

Post a comment