Android Project Structure in android Studio

In previous post, we have created hello world android application. In this post, I am going to explain structure of android application to understand it better.
When you created android application, your folder structure will look similar to below.

Lets understand above folder structure.

ApplicationManifest.xml:

ApplicationManifest.xml resides in src/main/.
Every application should have ApplicationManifest.xml in its root directory. It provides all important information to android system which system must have before it run the application.
We can declare following in ApplicationManifest.xml:

  • Package Name
  • Permissions of Application
  • Declaration of Activity , Services, broadcast receivers etc.
  • Minimum level of SDK and many more..

AndroidManifest.xml

All java classes resides in src/main/java folder.
Activity is java class which actually supports a screen on UI. It is like a frame in java.
Activity is predefine class in android and every screen must inherit to some activity to create a UI.
HelloWorldActivity.java

res:

res(src/main/res) is folder which represents resource folder in android. It has multiple sub folders.

drawable:

It is the folder in which you put images which you are going to use in your android app.

layout:

It is the folder in which you have layout xml file. Layout file represents design of the screen. Every activity class has layout file corresponds to it. If you notice in HelloWorldActivity.java , we have put following code.

setContentView actually binds layout to a activity. In our case, layout name is activity_hello_world.xml. If you open activity_hello_world.xml, you will see below screen.

You can drag and drop widgets to screen using design interface.
You can click on Text as highlight above and you will see below xml
activity_hello_world.xml

You can edit in above xml file also to make layout related changes.

mipmap :

This folder contains android application icon in different size.

values:

This folder will contains xml file which will have constant in it.
For example:
string.xml file have all strings declared in it, so you don’t have to hardcode anything in your java code.

Why you should not hardcode:
You have all strings in english as of now and you are going to release your application in french then if you hardcode everywhere then you need to change in search the strings and change in java code but if you do not hardcode anything, you just have to convert strings.xml strings in french and it will work.

Gradle scripts:

Gradle is open source automation tool similar to ant and maven. It is used to build project and include dependency in android studio. We will more about it later.

Exercise:

Lets do a small exercise to see if you understand above structure or not.
You need to make changes in hello world app and make output as below.

Do not hardcode “Welcome to Java2blog” in layout file. Put string contant in strings.xml

Solution:

    • Click on activity_hello_world.xml in project structure.
    • Drag “Hello world” string in Hello world app to center part using design layout.
    • Add string constant with “Welcome to Java2blog” in strings.xml as below:
  • Make change in TextView attribute android:text as “@string/welcome_java2blog”
  • Bingo!! You have completed basic exercise.

Was this post helpful?

Related Posts

  • 25 June

    Convert Roman Number to Integer in Python

    Table of ContentsHow to Convert Roman Number to Integer in PythonHow to convert roman number to integer in python?Using the if...else statement to convert roman number to integer in Python.Using classes and a dictionary to convert roman number to integer in Python.Using the roman module to convert roman number to integer in Python.ConclusionWas this post […]

  • 11 June

    Remove Single Quotes from String in Python

    Table of ContentsRemove single quotes from string in Python.How to remove single quotes from string in Python?Using the replace() function to remove single quotes from string in Python.Using a for loop to remove single quotes from string in Python.Using the join() function to remove single quotes from string in Python.Using the re module functions to […]

  • 11 June

    Escape Backslash Character in Python

    Table of ContentsEscape backslash character in python.How to use escape backslash character in python?Using the escape backslash character in python to represent whitespace characters.Using the escape backslash character in python to turn special characters into ordinary characters.Using the escape backslash character in f-strings in Python.Using the escape backslash character in raw strings in Python.Was this […]

  • 11 June

    Remove Parentheses From String in Java

    Table of ContentsJava StringsRemove Parentheses From a String Using the replaceAll() MethodRemove Parentheses From a String by TraversingConclusionWas this post helpful? Java uses the Strings data structure to store the text data. This article discusses methods to remove parentheses from a String in Java. Java Strings Java Strings is a class that stores the text […]

  • 11 June

    Break out of function in Python

    Table of ContentsBreak out of function in PythonHow to break out of function in Python?Using the return statement to break out of function in PythonUsing the try and except block to break out of function in PythonUsing the sys.exit() function to break out of function in PythonConclusionWas this post helpful? In this post, we will […]

  • 11 June

    Check if Object Is Iterable in Python

    Table of ContentsWhat are iterables in Python?How to check if object is iterable in Python?Using the iter() function to check if object is iterable in PythonUsing the for loop to check if object is iterable in PythonUsing the isinstance() function to check if object is iterable in PythonConclusionWas this post helpful? In this post, we […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.