The Android developer roadmap has been divided into five modules, each of which covers a different area of the Android development ecosystem. In the previous post, we covered key aspects of Android's architecture, such as the primary Android languages, the OS, the Android Platform, and the App Manifest.
In part two, we’ll cover the next three sections of our Android Roadmap:
Let’s get started!
In Android development, app components act as entry points that let users and other systems communicate with your application. Each component is created and destroyed according to a specific function and lifecycle.
Now let us talk about each element:
An activity is an independent and reusable component that interacts with the user by providing UI-relevant resources. All Android applications must have at least one activity to enter the app and interact with users.
Each activity has its own lifecycle, which is an important concept in activity and resource management. The Activity class provides a basic set of callback methods that notify an activity when a lifecycle state changes.
The lifecycle sequence shown in the following figure will be used to determine when to call the callback method:
With lifecycle callback methods, you can specify how your activity behaves and effectively manage your resources. In this section, we’ll discuss the six core callback methods below:
To create an activity, you must first create a class that is a subclass of the Activity class. To support compatibility with Themes, Fragments, and other components in modern Android development, the Jetpack library provides advanced Activity classes such as AppCompatActivity, FragmentActivity, and ComponentActivity. You can create a basic activity with the following code:
For your app to use activities, you must declare them on the App Manifest as seen in the following example:
A service is an entry point that is designed to perform functions for remote processes and to run longer-running operations in the background, such as a music player or YouTube video player.
A service has its own dedicated lifecycle and provides two types of information that tells the system how to start and manage services:
As you can see in the figure below, a service’s life cycle depends on how it was created.
According to the Android documentation, the figure above "distinguishes services created by startService() from those created by bindService()," but regardless of how services are started, they can potentially allow clients to bind to them.
To create a service, you must create a class as a subclass of the Service class, as shown in the example below:
Next, for your app to be able to use the service, you must declare it on the App Manifest:
A broadcast receiver is a listener that can be set up to receive broadcast messages from the Android system and other Android apps. According to the Android documentation, broadcasts are used to send messages across apps and outside of the normal user flow, such as when the system boots up or the device starts charging.
Broadcast receivers, unlike activities and services, do not have dedicated lifecycles. Instead, until it is unregistered, it will listen to all assigned event messages.
To create a broadcast receiver, you must first create a class that is a subclass of the Broadcast Receiver class, as shown in the following example:
Next, for your app to be able to use the service, you must declare it on the App Manifest:
A content provider determines how your application's data is accessed and shared with other applications. According to the Android Docs, a content provider enables your app to share any type of persistent data, whether it is stored in a file system, a SQLite database, a Jetpack Room, or on the web.
Content providers protect data by requiring specific permissions. If a requesting application lacks the necessary permissions, it cannot query the content provider's data.
This concludes part two of the Android Developer Roadmap. This section covered the important parts of the App components and lifecycles, so you have a better grasp of how Android components and their lifecycles work.
Again, don’t be intimidated by the amount of information on this roadmap. Check out the sections that seem the most helpful to you to understand Android development.