Android Studio Hello World First Example

Download and Install Android Studio: First, you need to download and install Android Studio on your computer. You can download it from the official website of Android Studio.

The below program is developed with Android Studio Chipmunk | 2021.2.1 Patch 2

Create a new project: File->New ->New Project (Ctrl+Shift+N)

Select a activity type here we selected Empty Activity

Android Studio Hello World Example Activity Selection
Android Studio Hello World Example Activity Selection

Provide Project Name MyFirstApp, package name, Save location , language and Minimum SDK.

Then click on finish.

Wait for Gradle to build- Android Studio will now take a few moments to create the project and download any necessary files.

Android Studio Hello World Example Project Creation
Android Studio Hello World Example Project Creation

Project Explorer will look like as below.

Android Studio Hello World Example Project Explorer
Android Studio Hello World Example Project Explorer

MainActivity.java

MainActivity.java is a Java class file that acts as the entry point for an Android app.

It is responsible for handling the main user interface of the app and managing the user’s interactions with the app.

The file contains the code that is executed when the app is launched, and it also defines the layout of the app’s user interface.

It is a crucial component of any Android app and serves as the foundation for its functionality.

Activity_main.xml

Activity_main.xml is an XML layout file that defines the user interface of the main activity of an Android app.

It is used to create the visual elements of the app’s user interface, such as buttons, text fields, and images.

The file is divided into a hierarchy of views, where each view represents a graphical element on the screen.

The XML file can be edited using the Android Studio layout editor or by manually editing the XML code.

It plays a crucial role in the development of any Android application’s user interface.

Activity_main.xml shows design mode to see the code click on the code as shown below.

Activity_main.xml
Activity_main.xml

Run the First Android App

Now, click on the green “play” button on the top toolbar or go to “Run” > “Run ‘app'” to run the application. Select the emulator or a connected device to run the application on.

Here We have connected our mobile phone.

Run Android Project
Run Android Project

Result of First Android App

After the application runs, you should see a screen with the text “Hello, World!” displayed in the center.

Android First App Output
Android First App Output

Updating Activity_main.xml

Hello World Android Output
Hello World Android Output

change android:text to set another text.