Android Basics: App Anatomy, Activities, And Exploring Android Studio

Abhisek Samantaray
7 min readJul 4, 2020

Hey Dev!, Hope you are doing well and Great.

Installation of Android Studio

I hope that you have already installed Android Studio in your System if not you can go to these links (Below) As per your operating System And install it.

For Windows User: https://www.youtube.com/watch?v=0zx_eFyHRU0

For Linux User: https://www.youtube.com/watch?v=VrOhA-I3aFs & https://www.youtube.com/watch?v=axtVId9ASmY

For Mac User: https://www.youtube.com/watch?v=xcuySGDzho4

Configuration of an Android Studio Project And Understanding Basic Terminologies

Now after launching the Android Studio, Welcome to Android Studio Window will Appear

Welcome to Android Studio Window

Now click Start a new Android Studio project, Create a New project dialogue box appears where you have to choose an Activity.

Create New Project Window

Now what is an Activity in Android Studio?

An Activity is a single, focused thing that the user can do. Every app must have at least one activity as its entry point. Think of this entry-point activity as the main() function in other programs. An activity typically has a layout associated with it that defines how user interface (UI) elements appear on a screen.

You can understand better with this Example: When you are using either Whatsapp or Telegram, their entry-point activity displays the person’s name or the group’s name those who have sent messages, then after switching to a particular chat or group the Activity changes, and also same with Status and call activities in WhatsApp.

Choose an Activity and click Next. After that Configure Your project dialogue box appears

Next, you provide a name that you want to give your App.

Then there is a Package name which you don’t have to fill.

What is a Package name?

All Android apps have a package name. The package name uniquely identifies the app on the device; it is also unique in the Google Play store. don’t change it unless and until you want to publish your app in play store . if you want you can change but it is recommended not to change.

Now select your preferred language (Kotlin or java) as your wish.

Now what is SDK (Software development Kit) in Android?

As Android has different versions and each version have different features So select Minimum SDK up to which your App and it’s features can run.

Now after Configuring your project click finish. Then Gradle (What is Gradle it is discussed in the explore section down) will Built and Configure your Project.

After Successful Gradle sync, MainActivity.kt(For kotlin file) tab will Appear.

Exploring Project Pane

Make sure you all are in Project pane and Android view, if not you can change to the Android view by clicking on arrow mark there and then Android view.

Now Exploring the Project Pane:

There are only two main folders one is app and another one is Gradle Scripts.

Firstly in the app folder, there is three subfolders: manifests, java, res (resources) folder

Inside manifests folder there is an AndroidManifest.xml file that includes details that android system needs in order to run your app, including what activities are part of the app.

it is also the place where you would define any permissions like phone contacts, send data over the internet, or access hardware such as camera, etc.. that your app needed.

Now java folder includes com.example.android.helloworld, the other two files with the same name but in brackets, there is (androidTest) and another one is (test) that is used for code related to testing, such as unit tests.

now the thing is after expanding the com.example.android.helloworld folder then the MainActivity.kt file is present.

why the kotlin file is present in the java folder?

There are historical reasons why your Kotlin code appears in the java folder. That convention allows Kotlin to work with java code also very easily written in the Java programming language, even in the same project and app.

Your app’s class files are contained in three subfolders, as shown in the figure above. The com.example.hello.helloworld (or the domain name you have specified) folder contains all the files for an app package.

Now inside res (resources)folder, there are four more subfolders: layout, mipmap, values , drawable.

The res folder holds resources. Resources in Android are static content used in your apps. Resources include images, text strings, screen layouts, styles, and values such as hexadecimal colors or standard dimensions.

expand the layout folder to view your activity_main.xml file.

What is activity_main.xml file?

Your Activity is usually associated with a UI (User Interface)layout file, defined as an XML file in the res/layout directory. That layout file is usually named after its activity. In this case, the activity name is MainActivity, so the associated layout is activity_main.

the other folders: drawable, mipmap, value is also associated with the resources that are used in the app icon and in the activity_main.xml file.

Now coming to Gradle Script folder:-

firstly What is Gradle?

Gradle is a build automation system that uses a domain-specific language to describe the app’s project structure, configuration, and dependencies. When you compile and run your app, you see information about the Gradle build running. You also see information about the Android Package Kit (APK) being installed. (APK is the package file format that the Android operating system uses to distribute and install mobile apps.)

there is no need to understand all folders in Gradle Script only a few are important

what is build.gradle(Project: HelloWorld) file.

This file contains the configuration options that are common to all the modules that make up your project. Every Android Studio project contains a single, top-level Gradle build file. This file defines the Gradle repositories and dependencies that are common to all modules in the project.

what is build.gradle(Module:app) file.

In addition to the project-level build.gradle file, each module has a build.gradle file of its own. The module-level build.gradle file allows you to configure build settings for each module. This build.gradle file is the one you most often edit when changing app-level build configurations. For example, you edit this build.gradle file when you change the SDK level that your app supports, or when you declare new dependencies in the dependencies section.

Understanding the Anatomy(Working) Or Behind the Scenes of an App

When we launch an app by clicking its icon then it launches the activity specified in the activity_main.xml file.

MainActivity is an example of an Activity. An Activity is a core Android class that draws an Android app user interface (UI) and receives input events.

Many Programming languages define a main method that executes the program. But in Android apps don’t have a main method instead of main() Android uses AndroidManifest.xml file that indicates that MainActivity file should be launched when the user clicks the app’s icon.

To launch an activity, the Android OS uses the information in the manifest to set up the environment for the app and construct the MainActivity. Then the MainActivity takes charge of it.

Each activity has an associated layout file. The activity and the layout are connected by a process known as layout inflation. When the activity starts, the views that are defined in the XML layout files are turned into Kotlin view objects in memory.

Exploring the activity_main.xml file Or the layout file

What is a layout file?

A layout file is an XML file that expresses what an activity actually looks like. A layout file does this by defining views and defining where the views appear on the screen.

what are views?

Views are things like image, text, buttons that extend the View class. There are many types of views like ImageView, TextView, Button, and CheckBox.

make sure you are in activity_main.xml file and code preview mode.

here you can write the XML code for your UI(User Interface) part of the App.

Now switching to design mode where if you make any changes the XML file editor will make changes to your code(XML file) automatically.

Mostly developers work with design mode in activity_main.xml file while making apps and to make some changes they switch to code mode.

after opening the design mode firstly there are two screens you will be displayed.

first, the white mode screen which is called design screen where you can see how your UI (User Interface) will look after every change.

the second one, the blue screen which is called Blueprint of the app where you can see which view is at what distance from the parent layout,etc…

what is palette?

Palette is a place where you have all the Views and widgets which you want to include in the app.

What is a component Tree?

The component tree provides a visual overview of the hierarchy of the user interface design. … Similarly, selecting a view from the device screen layout will select that view in the component tree hierarchy.

there are many layouts like constraint, relative, linear.you can change the layout as per app requirements.

By default, Android Studio gives you constraint layout as it is comfortable and easy as compared to linear and relative one.

So that’s it for this Blog. Hope I have expressed in simple words.
Happy Learning

Thank you!!

--

--