Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Components of Android Application
2.1.
Activities
2.2.
Services
2.3.
Content Providers
2.4.
Intents
2.5.
Broadcast Receivers
2.6.
Widgets
2.7.
Notifications
3.
Directory Structure of Android App
3.1.
Java folder
3.2.
Manifests Folder
3.3.
Gradle Scripts folder
3.4.
Resource (res) folder
3.4.1.
res/layout folder
3.4.2.
res/drawable folder
3.4.3.
res/values folder
4.
FAQs
5.
Key Takeaways
Last Updated: Mar 27, 2024

Android App Components and Folder Structure

Author Vasu Bansal
0 upvote
Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

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.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Directory Structure of Android App

Before we dive deep into coding our Android application, it is essential to understand the directory structure of our app. The android project contains different types of resource files, app modules and source code files. We will look at all of the Android app's directories and files in the following subsection.

Java folder

The Java folder contains the source code files (.java/.kt) that we create during the app development process. Other than this, the Java folder also contains additional test files. This folder contains the MainActivity.java file. 

The following is the sample directory structure of the Java folder inside our Android application.

 

Manifests Folder

The manifests folder possess the AndroidManifest.xml that is used to create the Android application. This file contains details about our application, such as the Android version, metadata, the states package for the Kotlin file, and other components. It serves as a bridge between the android operating system and our application.

The directory structure of the manifests folder in our Android application looks as follows.

Gradle Scripts folder

Gradle stands for "Automatic Build System". It consists of a set of files that create a build configuration that can be applied to all of our application's modules. Build scripts are used in build.gradle (Project), and plugins and implementations are used in build.gradle (Module) to create configurations that can be applied to all of our application modules.

The directory structure of the gradle scripts folder in our Android application looks as follows.

Resource (res) folder

The resource folder is the most significant folder because it holds all of our android application's non-code resources, including photos, XML layouts, and UI strings. 

The following are some subdirectories inside our application's resource folder.

res/layout folder

The layout folder contains all of the XML layout files that we utilised to define our application's user interface. The activity_main.xml file is also located in this folder.

The following is the sample directory structure of the layout folder.

res/drawable folder

It contains the various sorts of pictures utilised in the application's development. We need to place all of the photos in a drawable folder for the application's development.

The following is the sample directory structure of the drawable folder.

res/values folder

A lot of XML files, such as strings, dimens, colours, and styles definitions, are found in the values folder. The strings.xml file is one of the most crucial files as it contains the application's resources. 

The following is the sample directory structure of the values folder.

FAQs

  1. What are the differences between activity and services in Android?
    Both activities and services are the basic building blocks of an Android application. Generally, activities handle the User Interface part, and services handle the task based on the input provided by the user.
     
  2. What are the benefits of intent in Android?
    You may use intents to customise your app's user experience or ask other apps to do things like taking photos, sending emails and SMS messages, and even display places on maps and play media.
     
  3. Which file is used to define the application's icons displayed on the home screen?
    The application's icons are defined in the launcher.xml files, which is present in the location app/res/midmap. Depending on the type of devices, this file contains icons of varying densities. 

Key Takeaways

Cheers if you reached here!!

This blog aims to introduce you to the components of an Android application and the directory structure of your Android app. To read more about Android application resources, refer to this blog on the Coding Ninjas website.

Yet there is never an end to the learning process, so check out our Android Development Course on the Coding Ninjas Website to learn everything you need to know about Android development and how to design the applications of future. You can also consider our Online Coding Courses such as the DSA in PythonC++ DSA CourseDSA in Java Course to give your career an edge over others.

 

Live masterclass