Category test

An <intent-filter> element also lists categories as subelements. For example:

<category android:name= <category android:name=

"android, "android.

intent intent

.category.DEFAULT" /> .category.BROWSABLE" />


Note that the constants described earlier for actions and categories are not used in the manifest file. The full string values are used instead. For instance, the "android.intent.category.BROWSABLE" string in the example above corresponds to the CATEGORY_BROWSABLE constant mentioned earlier in this document. Similarly, the string "android.intent.action.EDIT" corresponds to the action_edit constant.

For an intent to pass the category test, every category in the Intent object must match a category in the filter. The filter can list additional categories, but it cannot omit any that are in the intent.

In principle, therefore, an Intent object with no categories should always pass this test, regardless of what's in the filter. That's mostly true. However, with one exception, Android treats all implicit intents passed to startActivityQ as if they contained at least one category: "android.intent.category.DEFAULT" (the category_default constant). Therefore, activities that are willing to receive implicit intents must include

"android.intent.category.DEFAULT" in their intent filters. (Filters with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings are the exception. They mark activities that begin new tasks and that are represented on the launcher screen. They can include

"android.intent.category.DEFAULT" in the list of categories, but don't need to.) See Using intent matching, later, for more on these filters.)

Was this article helpful?

0 0

Post a comment