Creating Android Application Components
An Android application may contain the following components:
- Activity: implements a window where you place your UI to interact with the user.
- Fragment: represents a behavior or a part of user interface in an activity.
-
Application: an Android package, i.e. an
.apk
archive that contains the contents of an Android app and the installer. - Service: represents an application's desire either to perform an operation without interacting with the user, or to supply functionality for other applications.
- Broadcast Receiver enables the reception of intents from the system or another application without running other components of this application.
- Remote Interface: an Android Interface Definition Language (AIDL) interface used for interprocess communication.
All Andoid application components are created in the same way. When you create a new component, a class that implements this component is generated and the component is automatically declared in the AndroidManifest.xml file.
On this page:
- Creating an Android component
- Navigating between an activity or a fragment and its related layout definition file
- Navigating from a component to its declaration in the AndroidManifest.xml file
Creating an Android component
- In the Project view, right-click the destination package where the application classes are stored and select New | Android Component from the context menu.
- In the New Android Component dialog box that opens, specify the following:
- In the Name text box, type the name of the class that implements the component.
- From the Kind drop-down list, select the required component type:
- In the Label text box, type the component title that will be displayed to the user.
- For an Activity, select the Mark as startup activity check box to have this activity displayed by default when the application starts.
-
For an Activity or a Fragment, select the Create layout file check box to have IntelliJ IDEA generate the stub of a related layout definition
(content view).
In the Create Layout dialog box that opens, specify the layout name, its root element,
and the folder where the layout definition will be stored relative to the
res
folder.-
If your application does not need to be compatible with various Android devices and, therefore, no multiple screens
support is required, accept the default
layout
subfolder. - To provide alternative resources, specify the resource qualifiers that determine a specific device configuration. Move the relevant qualifiers from the Available qualifiers list to the Chosen qualifiers list and specify their values. IntelliJ IDEA appends all the selected qualifiers to the Directory name field with a dash character as separator.
For details, see Creating Resources.
-
If your application does not need to be compatible with various Android devices and, therefore, no multiple screens
support is required, accept the default
Note that when you create an activity, a service or a broadcast receiver, they are automatically registered in the androidmanifest.xml
file.
Navigating between an activity or a fragment and its related layout definition file
You can jump from the source code of an activity or a fragment to the layout definition file which represents its content view and vice versa, from the layout definition to the source code.
- To jump from a component to its related layout definition, open the source code of the component, and do one of the following:
- To jump from a layout definition to the source code of the corresponding component, open the layout definition file in the text mode and do one of the following:
Navigating from a component to its declaration in the AndroidManifest.xml file
As soon as a component is created, it is immediately declared in the AndroidManifest.xml
file.
For components of the activity, fragment, service, and broadcast receiver type,
you can jump to this declaration right from the component source code.