Application Fundamentals

Android applications are written in the Java programming language. The Android SDK tools compile the code-along with any data and resource files-into an Android package, an archive file with an .apk extension. All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application.

Application Components

Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Some components are depend on each other and not all components are actual entry points, but each one plays a specific role and exists as its own entity. Each component is a unique building blocks that define your application's overall behavior.

There are four different types of application components, each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

Here are following four main application components that can be used within an Android application:

Components Description
Activities Activities dictate the UI and handle the user interaction to the smartphone screen
Services Services handle background processing associated with an application.
Broadcast Receivers Broadcast Receivers handle communication between Android OS and applications.
Content Providers Content Providers handle data and database management issues.

Activities :

An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails.
If there are more than one activity in an Application then one of the activity should be marked as the activity that is presented when the application is launched.

An activity is implemented as a subclass of Activity class as given below -

public class MainActivity extends Activity

Services :

A service is a component that perform work for remote processes or runs in the background to perform long-running operations. A service does not provide a user interface. For example, it might fetch data over the network without blocking user interaction with an activity, or a service might play music in the background while the user is in a different application.

A service is implemented as a subclass of Service class as given below -

public class MyService extends Service

Content providers :

Content provider manages a shared set of application data. You can store the data in the file system, on the web, an SQLite database, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information.

Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.

A content provider is implemented as a subclass of ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.

public class MyContentProvider extends ContentProvider

Broadcast receivers :

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system-for example, a broadcast announcing that the battery is low, the screen has turned off, or a picture was captured.
Applications can also initiate broadcasts-for example, to let other applications know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs.

A broadcast receiver is implemented as a subclass of BroadcastReceiver class and each broadcast is delivered as an Intent object.

public class MyReceiver  extends  BroadcastReceiver

Additional Components

There are some additional components which will be used in the construction of above mentioned entities, their logic, and wiring between them. These components are following:

Components Description
Layouts View hierarchies that control screen format and appearance of the views.
Fragments Represents a behavior or a portion of user interface in an Activity.
Manifest Configuration file for the application
Views UI elements that are drawn onscreen including buttons, lists forms etc.
Resources External elements, such as strings, constants and drawables pictures.
Intents Messages wiring components together.