Registering Activities and Other Application Components Android

Each Activity within the application must be defined within the Android manifest file with an <activity> tag. For example, the following XML excerpt defines an Activity class called AudioActivity:

This Activity must be defined as a class within the com.androidbook.multimedia package. That is, the package specified in the <manifest> element of the Android manifest file. You can also enforce scope of the activity class by using the dot as a prefix in the Activity name:

Or you can specify the complete class name:

Designating a Primary Entry Point Activity for Your Application Using an Intent Filter
An Activity class can be designated as the primary entry point by configuring an intent filter using the Android manifest tag <intent-filter> in the application’s AndroidManifest.xml file with the MAIN action type and the LAUNCHER category.

The following tag of XML configures the Activity class called MultimediaMenuActivity as the primary launching point of the application:

Configuring Other Intent Filters
The Android operating system uses Intent filters to resolve implicit intents. That is, Intents that do not specify the Activity or Component they want launched. Intent filters can be applied to Activities, Services, and BroadcastReceivers. The filter declares that this component is open to receiving any Intent sent to the Android operating system that matches its criteria.

Intent filters are defined using the <intent-filter> tag and must contain at least one <action> tag but can also contain other information, such as <category> and <data> blocks. Here we have a sample intent filter block, which might be found within an <activity> block:

This intent filter definition uses a predefined action called VIEW, the action for viewing particular content. It is also BROWSABLE and uses a scheme of geoname so that when a Uri starts with geoname://, the activity with this intent filter launches.You can read more about this particular intent filter in Chapter “Using Location-Based Services (LBS) APIs.”

Registering Services and Broadcast Receivers

All application components are defined within the Android manifest file. In addition to activities, all services and broadcast receivers must be registered within the Android Manifest file.

  • Services are registered using the <service> tag.
  • Broadcast Receivers are registered using the <receiver> tag.

Both Services and Broadcast Receivers use intent filters. You learn much more about services, broadcast receivers, and intent filters later in the book.

Registering Content Providers

If your application acts as a content provider, effectively exposing a shared data service for use by other applications, it must declare this capability within the Android manifest file using the <provider> tag. Configuring a content provider involves determining what subsets of data are shared and what permissions are required to access them, if any.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Android Topics