Android Hello World Example Project File Structure

This article will show you how to use android studio to create an android Hello World example. It also explains the main example files and their role and relation.

1. Create android hello world example steps.

You can read the article Android Development Environment Setup first if you do not know.

  1. Open android studio by clicking Widows Start  —> Android Studio —> Android Studio.
  2. Click Start a new Android Studio project link in the Welcome to Android Studio windows dialog.
  3. In the Create New Project window, input android project settings such as Application name ( for example HelloWorldExampleProject ), Company domain ( for example ), and browse to select the Project location ( project saved directory), then click the Next button.
  4. In the Add an Activity to Mobile window, choose the default activity for this project. Select ” Empty Activity ” in this example then click the Next button.
  5. In the Customize the Activity window dialog, input the Activity Name(MainActivity) and the Layout Name(activity_main), you can use the default setting values here, click the Next button.
  6. Click the Finish button to complete the setup wizard.

2. Android project file explanation.

  1. Now the new android project has been created completely, you can see there has a lot of files in the android studio left panel tree.
  2. The most important three files are AndroidManifest.xml,, and activity_main.xml, we will explain them one by one.
  3. The below picture shows the relationship between the above three files.
  4. Below is the above 3 files in the android hello world project.
    │      │
    │      ├─main
    │      │  │  AndroidManifest.xml
    │      │  │
    │      │  ├─java
    │      │  │  └─com
    │      │  │      └─dev2qa
    │      │  │          │
    │      │  │          └─www
    │      │  │              └─helloworldexampleproject
    │      │  │            
    │      │  │
    │      │  └─res
    │      │      ├─layout
    │      │      │      activity_main.xml
  5. AndroidManifest.xml: When the android app starts, the android operating system will read this file first, it is an XML file that includes the default activity information. Android will create the activity component configured in it. From this file, we can see the default activity is MainActivity. If you want android to use another activity as a startup activity, you can change the settings here.
  6. Double click this file in the left panel, you can see it extends the class, and it should override the onCreate(Bundle savedInstanceState) method. This method will be executed when this activity is called.
    public class MainActivity extends AppCompatActivity {
        protected void onCreate(Bundle savedInstanceState) {
  7. The setContentView(R.layout.activity_main) method in the above code is used to set the content view layout file. The layout file will control how to display the UI components in activity view. And it is referenced with R.layout.activity_main. And activity_main is just the layout file name.
  8. Android tools create the R class dynamically before compiling the java source code, it includes all the resource files such as layout, UI components, image, string, id, etc. You can use it to reference all the resources.
  9. activity_main.xml: This file located in the res/layout folder. It defines what components to display and how to display them in referenced activity view. Double click this file, you can see the content in the right panel, it has a Design view and a Text view, you can click the bottom Design and Text tab to switch.
  10. Our example activity_main.xml has been customized to below. We add an id to the TextView component, set it’s layout width and height value to match_parent, change the text, text color, size, and style.
    <?xml version="1.0" encoding="utf-8"?>
    < xmlns:android=""
            android:text="Hello World from"
            app:layout_constraintVertical_bias="0.298" />
  11. Right-click, click the ” Run MainActivity ” menu from the popup menu list or click the Run button in the top toolbar to execute the app.
  12. In the Select Deployment Target windows dialog, select the virtual device that you have already added. Then wait for it to startup, after some time, you can see the app displayed in a device simulator.

3. How to get the TextView component in java code.

  1. From the above activity_main.xml, we add an id attribute to the TextView component. If you want to get that component in java code, you can use the below code.
     TextView textView = (TextView) this.findViewById(;
  2. Change java code to below for MainActivity onCreate method.
        protected void onCreate(Bundle savedInstanceState) {
            TextView tv = (TextView) this.findViewById(;
            tv.setText(" is a good tutorial website.");
  3. Do not forget to import the below classes.import; import android.widget.TextView;
  4. Now run again, you can find text content and color is changed in the device simulator.

4. Create An Android APK File.

  1. Click ” Build —> Build APK ” in the Android Studio toolbar.
  2. After building you can see a popup dialog at the Android Studio right bottom corner. The dialog title is Build APK. Click the Show in Explorer link in the popup dialog to show the APK file in windows explorer.
  3. Generally, the APK file is saved in your android output folder like this HelloWorldExampleProject\app\build\outputs\apk, you can get it there and copy it to your Android Simulator or physical device to run it.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.