Android for Beginners
About Lesson

Android applications are built using a set of essential building blocks known as application components. Each of these components serves a distinct purpose and has a unique lifecycle that defines how it is created and destroyed. Let’s explore these components in detail.

1. 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. Activities work together to form a cohesive user experience in the application.

public class MainActivity extends Activity {
}

2. Services

Service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application.

public class MyService extends Service {
}

3. Content Providers

Content Provider manages a shared set of application data. Through the content provider, other applications can query or 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.

public class MyContentProvider extends ContentProvider {
   public void onCreate(){}
}

4. Broadcast Receivers

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 screen has turned off, the battery is low, or a picture was captured.

public class MyReceiver extends BroadcastReceiver {
   public void onReceive(context,intent){}
}

5. Activating Components

Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an Intent. Intents bind individual components to each other at runtime, whether the component belongs to your application or another.