An Android application is a single installable unit which can be started and used independently of other Android applications.
An Android application can have one application class which is instantiated as soon as the application starts and it is the last component which is stopped during application shutdown.
An Android application consists of Android software components and resource files.
Android application components can connect to components of other Android applications based on a task description (Intent). This way they can create cross-application tasks. The integration of these components can be done in a way that the Android application can still work flawless, even if the additional components are not installed or if different components perform the same task.
The following software components can be defined in Android applications.
An activity is the visual representation of an Android application. An Android application can have several activities.
Activities use views and fragments to create the user interface and to interact with the user. Both elements are described in the next sections.
A service performs tasks without providing an user interface. They can communicate with other Android components, for example, via broadcast receivers and notify the user via the notification framework in Android.
A broadcast receiver (receiver) can be registered to listen to system messages and intents. A receiver gets notified by the Android system if the specified event occurs.
For example, you can register a receiver for the event that the Android system finished the boot process. Or you can register for the event that the state of the phone changes, e.g., someone is calling.
A content provider (provider) defines a structured interface to application data. A provider can be used for accessing data within one application, but can also be used to share data with other applications.
Android contains an SQLite database which is frequently used in conjunction with a content provider. The SQLite database would store the data, which would be accessed via the provider.
Instances of the class android.content.Context provide the connection to the Android system which executes the application. It also gives access to the resources of the project and the global information about the application environment.
For example, you can check the size of the current device display via the Context.
The Context class also provides access to Android services, e.g., the alarm manager to trigger time based events.
Activities and services extend the Context class. Therefore they can be directly used to access the Context.
The following description gives an overview of the most important user interface related component and parts of an Android application.
Activities are the base for the user interface in Android. They have already been introduced in Section “Activity”.
Fragments are components which run in the context of an activity. A fragment encapsulates application code so that it is easier to reuse them and to support devices of different size.
The following picture shows an activity called MainActivity. On a smaller screen it shows only one fragment and allows the user to navigate to another fragment. On a wide screen it shows those two fragments immediately.
Views are user interface widgets, e.g., buttons or text fields. Views have attributes which can be used to configure their appearance and behavior.
A ViewGroup is responsible for arranging other views. It is also known as layout manager. The base class for these layout managers is the android.view.ViewGroup class which extends the android.view.View class which is the base class for views.
Layout managers can be nested to create complex layouts.
The user interface for activities is typically defined via XML files (layout files). It is possible to define layout files for different device configuration, e.g., based on the available width of the actual device running the application.
Widgets are interactive components which are primarily used on the Android home screen. They typically display some kind of data and allow the user to perform actions with them. For example, a widget can display a short summary of new emails and if the user selects an email, it could start the email application with the selected email.
To avoid confusion with views (which are also called widgets), this text uses the term home screen widgets, if it speaks about widgets.