Introduction
In this blog, we will discuss the fundamental components of an Android application and understand the directory structure of our application. An android application is a combination of loosely tied components along with a lot of associated meta-data. The application code is very well segregated and categorised into different subdirectories under the application. In the next section, we will start by learning about the android application components.
Components of Android Application
An Android application is composed of a few essential building blocks. The manifest file of our Android application provides a description of each component and binds these loosely connected components. The app's metadata, device setup, platform requirements, external libraries, and required permissions are all included in the manifest file. An android app is made up of the following main components as listed below:
Activities
Activity is an application component that provides a screen where users interact the most. An activity can be shown as a part of the application screen itself or a floating activity (an activity that runs in the background). Activity has a complete lifecycle, starting with onCreate and starting the application. The application operates well after being created and started, and the system may pause it anytime later in case of interruptive events. If the application is no longer in use, it can be stopped and destroyed. The system can restart a previously closed application as well.
Java Code:
public class MainActivity extends Activity {
}
Kotlin Code:
class MainActivity : AppCompatActivity() {
}
To read more about activities in Android, refer to the blog Android Activities on the Coding Ninjas Website.
Services
Services are like our app's unseen employees. These components work in the background, updating data sources and activities, prompting notifications, and broadcasting Intents. They also do some work while the applications aren't running.
Java Code:
public class YourServiceName extends Service {
}
Kotlin Code:
class YourServiceName : Service() {
}
To read more about services in Android, refer to the blog Android Services on the Coding Ninjas Website.
Content Providers
Content Providers are used to handling and persisting application data. They're also in charge of sharing data outside of the app's limitations. They have frequent interaction with the SQL databases. A specific application's Content Providers can be set to allow access from other apps and the Content Providers offered by other applications.
Java Code:
public class contentProvider_name extends ContentProvider {
public void onCreate(){}
}
Kotlin Code:
class contentProvider_name : ContentProvider() {
// overriding the onCreate method
override fun onCreate(): Boolean {}
}
To read more about content providers in Android, refer to the blog Android Content Providers on the Coding Ninjas Website.
Intents
Intents are a robust framework for exchanging messages between applications. They're utilised frequently throughout Android. Intents can be used to start and terminate activities and services, broadcast messages to the entire system or a specific activity, service, or broadcast receiver, or request action on a particular piece of data.
To read more about intents in Android, refer to the blog Android Intents and Intent Filter on the Coding Ninjas Website.
Broadcast Receivers
They are referred to as intent listeners because they allow your application to listen to intents that meet our matching criteria. Broadcast Receivers enable our application to respond to any received intent, making them ideal for event-driven applications.
To read more about broadcast receivers in Android, refer to the blog Android Broadcast Receivers on the Coding Ninjas Website.
Widgets
These are the little visual app components that can be found on the device's home screen. They are broadcast receivers that let us develop dynamic, interactive application components that users may put on their Home Screen.
Notifications
Notifications are app alerts used to direct the user's attention to a specific app event without snatching the user's attention or interrupting their present activity. They're typically used to draw a user's attention to an application that isn't visible or running, such as within a Service or Broadcast Receiver. Email popups, Messenger popups, and so on are examples.