Android Hello World Example Project File Structure

This article will show you how to use android studio to create 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 article Android Development Environment Setup first if you do not know.

  1. Open android studio from start up menu.
    android studio startup menu
  2. Click Start a new Android Studio project.
    android studio create new project
  3. Input android project settings such as application name, domain name and project save directory in next dialog.
    android project settings
  4. Choose default activity for this project. Select ” Empty Activity ” in this example.
    add android project default activity
  5. Input activity name and it’s layout name, use default values here.
    activity name and layout settings
  6. Click Finish buton to complete the setup wizard.

2. Android project file explanation.

Now the new android project has been created completely, you can see there has a lot of files in left panel tree. The most important three file are AndroidManifest.xml , and activity_main.xml, we will explain them one by one.

The relationship between above three files.

AndroidManifest.xml MainActivity activity_main.xml relation

android project file list tree panel

  1. AndroidManifest.xml : When app start, android system will read this file first, it is a xml file which 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 startup activity, you can change the settings here.
  2. : Double click this file in left panel, you can see it extends class, and it should override onCreate(Bundle savedInstanceState) method. This method will be executed when this activity is called.
    public class MainActivity extends AppCompatActivity {
        protected void onCreate(Bundle savedInstanceState) {

    setContentView(R.layout.activity_main) in 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. activity_main is just the layout file name.

    Android tools create the R class dynamically before compiling the java source code, it include all the resource files such as layout, UI components, image, string, id etc. You can use it to reference all the resources.

  3. activity_main.xml : This file located at 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 right panel, it has Design view and Text view, you can click bottom Design and Text tab to switch. Our example activity_main.xml has been customized to below. We add 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" />
  4. Right click, click ” Run MainActivity ” menu from the popup menu list or click the Run button in top tool bar to execute the app.
    click run mainactivity to execute android app
  5. 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.
    android virtual device select list
    hello world example simulator output

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

From above activity_main.xml, we add a id attribute to TextView component. If you want to get that component in java code, you can use below code.

 TextView textView = (TextView) this.findViewById(;

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.");

Do not forget import below classes.
import android.widget.TextView;

Now run again, you can find text content and color changed in device simulator.

custom textview text and color output in device simulator

4. Create android apk file.

  1. Click ” Build —> Build APK ” in Android Studio tool bar.
    build android apk executable file
  2. After building you can see a popup dialog at right bottom. Click the link to show it in explorer.
    build android apk show in explorer
  3. Generally the apk file saved at your android ouput folder like below.
0 0 vote
Article Rating
Notify of

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

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x