How To Make An Android App - GeeksforGeeks

How To Make An Android App

Last Updated : 21 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Have you always wanted to make an Android app but got lost in the complexity of the Android Studio or the technical jargon used in the development process? Don’t worry, you have come to the right place. We are going to help you get started with your first Android app.

how to make an android app

The app that we are going to make will be a simple multi-screen app utilizing the concept of activities, where clicking on a button will take you to the next screen and vice versa. This simple app will serve as a good introduction to Android Studio and to the concepts of activities.

Want to learn how to create your own android applications from scratch  Check Out: Android App Development Course for Beginners – Self Paced

What is Android Studio?

Android Studio is the official Integrated Development Environment (IDE) for Android application development. It is a robust tool for developing high-quality Android applications. It includes all of the necessary tools for developing Android apps and also for code development, testing, and deployment. Android Studio provides all of the tools needed for developers to create an Android app.

It is a popular IDE for producing high-quality Android applications, suitable for both beginners and advanced developers.

If you don’t have Android Studio installed Check Out the link to install it right away: Download Android Studio

How to make an Android App?

The Android app that we are going to make is going to be a simple, multi-screen app that will introduce you to the concept of activities. You won’t need much coding to make this app, and if you follow the instructions, the app could be made very easily in an hour. So let’s see the steps:

Step 1: Create a New Project

  1. Open Android Studio.
  2. Click on “Start a new Android Studio project“.
  3. In the “Select a template” window, choose “Empty Views Activity“.
  4. Give your app a name – “TwoScreenApp”.
  5. Click “Next”.
  6. Configure the project details (package name, etc.) and click “Finish“.

image(1)

Step 2: Design First Screen Layout

In the activity_main.xml file let us design the layout for the first screen

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Screen"
android:textColor="@color/black"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnSecondActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Second Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textSize="32sp"
app:layout_constraintBottom_toTopOf="@+id/btnSecondActivity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.469"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"
app:layout_constraintVertical_bias="0.206" />

</androidx.constraintlayout.widget.ConstraintLayout>


This XML code defines two TextView and a Button for the first screen layout in an Android app with the following specifications:

  • XML code for an Android layout is provided.
  • Includes a large TextView displaying “First Screen” with specific text attributes.r.
  • Features a button labeled “Second Activity” with defined layout constraints.
  • Contains another TextView displaying “Hello World,” positioned below the first TextView and above the button.
  • Layout constraints ensure proper alignment of elements relative to the parent and each other.

Step 3: Design Second Screen Layout

Create a new XML layout file named activity_second.xml and design the layout for the second screen. Add a text view above the button, similar to the first screen layout.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Screen"
android:textColor="@color/black"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnFirstActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="First Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

This XML code defines a Button and a TextView for the second screen layout in an Android app. The code specifies:

  • TextView displays “Second Screen” with black text and a 40sp size.
  • TextView and Button are centered within their parent layout.
  • Both views adjust their dimensions to fit their content.
  • The button labeled “First Activity” has a bottom margin of 16 dp.
  • Views are constrained to the parent layout for proper alignment on the screen.

Step 4: Implement First Activity

In MainActivity.kt, we implement the functionality for the first screen. In the first screen we are going to create the functionality that is when the user clicks the button he is taken to the second screen. Let us see the code for it in the file named MainActivity.kt.

// MainActivity.kt

package com.example.msone

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val btnSecondActivity=findViewById<Button>(R.id.btnSecondActivity)
btnSecondActivity.setOnClickListener{
val intent= Intent(this,SecondActivity::class.java)
startActivity(intent)
}
}
}

In MainActivity.kt, we implement the functionality for the first screen. We get a reference to the button firstScreenButton using its ID with findViewById(). Then, we use a setOnClickListener to this button. When the button is clicked, the code inside the setOnClickListener block gets executed. Here, we create an intent to navigate to the second activity (SecondActivity) and start it using startActivity().

Step 5: Implement Second Activity

Now we are going create the file named SecondActivity.kt where we implement the functionality for the second screen. Similar to the first activity, when the user clicks the button he is taken to the first screen. Let us see the code for it in the file named SecondActivity.kt.

// SecondActivity.kt

package com.example.msone

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_second)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val btnFirstActivity=findViewById<Button>(R.id.btnFirstActivity);
btnFirstActivity.setOnClickListener{
val intent= Intent(this,MainActivity::class.java);
startActivity(intent)
}
}
}

In the above file, SecondActivity.kt, we are coding the behavior for the second screen of our app. Initially, we set the screen’s layout using setContentView() to display the UI elements defined in activity_second.xml. Then, we access the secondScreenButton using findViewById() and attach an OnClickListener. When this button is clicked, an intent is created to return to the first activity (MainActivity). Executing startActivity(intent) initiates the navigation back to the first screen. This setup enables users to switch between screens by tapping the designated button on the second screen.

Check Out: Introduction to Activities in Android

When you successfully implement the above code, it will allow the app to have two screens, each with its own functionality and the ability to navigate between them. When the user clicks the button on the first screen, it takes them to the second screen, and clicking the button on the second screen takes them back to the first screen.

Output:

firstscreen-(1)

1st Screen

second-screen

Second Screen

Also Read

Conclusion

We introduced you to how you can easily create a multi-screen app in Android Studio, teaching you the basics of activities. We have broken down the process into easy steps so that developers can quickly learn about basic ideas like activities, designing layouts, and moving around in Android Studio. By following these steps, even those with limited coding experience can build a functional app within an hour. The screens have basic text and a button to interconnect with the other screen, using which users can easily transition between different parts of the app. This simple Android app will serve as an accessible introduction to Android app development, solidifying the basics for beginners to create more complex applications.

FAQs on How to make an Android App?

What is Android Studio?

Android Studio is a IDE which is used for android app development. It provides us with lots of features which makes the development process easier.

Can I make an Android App if I am new to programming?

Yes, you can! We have tried to simplify the process, so even beginners can follow along and create their simple multi-screen app in just an hour.

What are activities in Android app development?

Activities are components in Android development, representing different screens or UI elements of an app.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads