Within an Android application the following main components are distinguished:
- Activities. An activity is a component that implements a screen to interact with the user.
- Fragments. A fragment implements a part of a screen implemented by an activity.
- Services. A service is a component that runs in the background mode.
- Broadcast Receivers enable reception of intents from the system or other applications without running other activities or services of the application.
- Android Remote Interface.
The creation procedure is identical for all types of components. Upon creation, a class that implements the component is created and the new 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
- In the Project view, right-click the destination package where the application classes are stored.
- On the context menu, click Android Component on the submenu. , then choose
- In the New Android Component dialog box that opens, specify
- In the Name text box, type the name of the class that implements the component.
From the Kind drop-down list, choose the desired component type:
- Broadcast Receiver
- Android Remote Interface
- In the Label text box, type the component title to be displayed to the
- If no title is specified, the label assigned to the entire application will be displayed.
- No label is specified for a remote interface.
- For an Activity, select the Mark as startup activity check box to have the 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
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 subfolder layout.
- To provide alternative resources, specify the resource qualifiers that determine the 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.
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 onw
of the following:
- Click the icon in the gutter area and choose the layout definition file in the Go To Related Files pop-up list.
- On the main menu, choose .
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:
- Click the icon in the gutter area.
- On the main menu, choose .
As soon as a component is created, it is immediately declared in the AndroidManifest.xml file. For components of the type activity, fragment, service, and broadcast receiver, you can jump to this declaration right from the component source code.
- Open the source code of the component, and click the icon in the gutter area.
- If the component also has a related layout definition file, choose AndroidManifest.xml in the Go To Related Files pop-up list.