IntelliJ IDEA 14.0.0 Web Help

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

  1. In the Project view, right-click the destination package where the application classes are stored and select New | Android Component from the context menu.
  2. 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:
      • Activity
      • Fragment
      • Application
      • Service
      • Broadcast Receiver
      • Remote Interface
    • 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.

Navigating between an activity or a fragment and its related layout definition file

  • To jump from a component to its related layout definition, open the source code of the component, and do one of the following:
    • Click the classTypeXml icon in the gutter area and choose the layout definition file in the Go To Related Symbol pop-up list.
    • On the main menu, choose Navigate | Related Symbol .
  • 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 classTypeJavaClass icon in the gutter area.
    • On the main menu, choose Navigate | Related Symbol .

Navigating from a component to its declaration in the AndroidManifest.xml file

  1. Open the source code of the component, and click the classTypeXml icon in the gutter area.
  2. If the component also has a related layout definition file, choose AndroidManifest.xml in the Go To Related Symbol pop-up list.

See Also

Last modified: 4 December 2014
comments powered by Disqus