Android Hello World Example

By | 2018-04-02T05:40:13+00:00 April 2nd, 2018|android|0 Comments

In this tutorial, we will see our first Android Hello World application.

Technologies :

  • Android 6.0 (Marshmallow)
  • Android SDK 27
  • Android Studio 3.0.1
  • Gradle

Android Hello World :

Open Android studio and create Android Hello World project. Give project name, project location and click on next.

Recommended: How install Android Studio on Windows 10 Operating System.

Android Hello World Example

Select Android API version, I am working on Android 6.0 (Marshmallow) and click on Next.

Android Hello World Example 2

Select an Empty Activity, Hello World message will appear on this activity.

Android Hello World Example 4

Give name to selected activity, as this is a main activity, I am giving the name as MainActivity and click on Finish.

Android Hello World Example 5

Now It will create our first Android Hello World project like below structure.

Project Structure :

Android Hello World Example Project

Project Overview:

Manifest: The is the Most Important File in Android as it contains all the Information about the app. It will act as a bridge between the application developer and android system.

Java: It contains all the .java files and classes where you actually code the backend of your app.

Res: This is the folder where it is mainly focused on front end and UI of the app

  1. Drawable: This  folder holds images used for the app
  2. Layout: This folder contains layout of the screen.
  3. Values: Colors contains the Hex values of colors used in app.
  4. Strings: It holds strings and app name
  5. Styles: It contains style components of the app.

Gradle Scripts: It provides the components and libraries required for app

MainActivity.java

package onlinetutorialspoint.com.helloworld;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="onlinetutorialspoint.com.helloworld.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Run Application :

We can run the Android applications in 2 different modes.

  • Running on Android Emulator and
  • Running on Actual Device

Running on Android Emulator :

Emulator is nothing an Android phone used for debugging and testing android apps. It’s more like an console where you see an output.

To run the application under Emulator mode, first we should configure the emulator.

Click on Run Button which you can see on Top Right of Toolbar, then Deployment Target wizard will open like below.

Create New Virtual Device :

Android Hello World Example 8

Select any mobile, prefer selecting an 5.5 phone and then click on next.

Android Hello World Select Device

Now you need to download the androd system image for your emulator, so recommended is select Nougat or Marshmallow  the download will be started.(it may take some time)

Android Hello World Download Emulator

Click on Finish.

Android Hello world Example 10

Now select the downloaded version of system image and click next.

Android Hello World Example 11

Click on Finish to create a new virtual Device

Android Hello World Example 12

Now when you click on Run again, you can find your newly created Virtual Device.

Select the Device and click OK.

Android Hello World Example 13

Emulator may take some time to load and after successful gradle build you will see the output like this

Android Hello World Example

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment