DEV Community

Cover image for Hands-on Android Development: Building Apps with Java & Android Studio
MANOJRATNA DUGGIRALA
MANOJRATNA DUGGIRALA

Posted on

Hands-on Android Development: Building Apps with Java & Android Studio

What is Android Studio?
Android Studio is the official Integrated Development Environment (IDE) for Android app development, built by Google. It provides developers with a powerful and flexible environment to design, develop, test, and debug Android applications efficiently.

Key Features of Android Studio:
✅ Intelligent Code Editor: It supports Java, Kotlin, and C++, offering features like code completion, refactoring, and real-time error checking.

✅ Layout Editor: A drag-and-drop UI designer that helps developers design app interfaces visually without writing XML manually.

✅ Gradle Build System: Automates and optimizes app building, making it easier to manage dependencies and configurations.

✅ Emulator for Testing: Provides a virtual Android device to test applications without needing a physical phone.

✅ APK Analyzer: Helps inspect the app’s APK file size and resources to optimize performance.

✅ Version Control Integration: Supports Git and other version control tools for collaborative development.

✅ Real-time Performance Profiler: Monitors CPU, memory, and network usage to optimize app performance.

Why Developers Love Android Studio?
User-friendly UI with a sleek and intuitive interface.
Deep integration with Google Services, including Firebase and Google Play.
Regular updates with the latest Android features and improvements.
Cross-platform support for Wear OS, Android TV, and more.
Android Studio is the ultimate toolkit for any developer looking to create high-performance Android applications!

In this Workshop, I Have Developed 4 Applications, and here is a detailed Overview of Every Application

1.Simple Counter App

This XML layout defines a simple Tap Counter App UI using a LinearLayout, two Button elements, and a TextView. Let’s break it down step by step.

  1. Root Layout - LinearLayout
<LinearLayout 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_margin="20sp" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="10" android:orientation="vertical" tools:context=".MainActivity"> 
Enter fullscreen mode Exit fullscreen mode
  1. Count Button
<Button android:layout_width="match_parent" android:layout_height="4dp" android:layout_weight="1" android:text="Count" android:onClick="count" android:textSize="24sp" /> 
Enter fullscreen mode Exit fullscreen mode
  1. TextView - Display Counter Value
<TextView android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="0sp" android:layout_weight="8" android:text="0" android:gravity="center" android:textSize="200sp"/> 
Enter fullscreen mode Exit fullscreen mode
  1. Toast Button
<Button android:layout_width="match_parent" android:layout_height="0sp" android:layout_weight="1" android:text="Toast" android:onClick="toast" android:textSize="24sp"/> 
Enter fullscreen mode Exit fullscreen mode

MainActivity.java File

  1. Package and Imports
package com.example.android_workshop; 
Enter fullscreen mode Exit fullscreen mode

This defines the package name of APP

import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; 
Enter fullscreen mode Exit fullscreen mode
  1. Defining Variables and Extending AppCompatActivity
public class MainActivity extends AppCompatActivity { TextView t1; int count = 0; 
Enter fullscreen mode Exit fullscreen mode
  1. onCreate() Method - Initializing the UI
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); 
Enter fullscreen mode Exit fullscreen mode
  1. Linking TextView from XML to Java
 t1 = this.<TextView>findViewById(R.id.text1); 
Enter fullscreen mode Exit fullscreen mode
  1. Handling Window Insets (Edge-to-Edge UI)
 ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); 
Enter fullscreen mode Exit fullscreen mode
  1. count() Method - Increasing the Counter
public void count(View view) { count++; t1.setText("" + count); } 
Enter fullscreen mode Exit fullscreen mode
  1. toast() Method - Showing a Toast Message
public void toast(View view) { Toast.makeText(MainActivity.this, "Hello my dear Connections" + count, Toast.LENGTH_LONG).show(); } 
Enter fullscreen mode Exit fullscreen mode

How Does the App Works?
1️⃣ Pressing the "Count" button increases the counter and updates the TextView.
2️⃣ Pressing the "Toast" button displays a message showing the current count.

Image description

  1. Simple Calculator App

This XML file defines the UI for a simple calculator app in Android using LinearLayout.

Overview:

  • Dark Theme (android:background="#000") for a stylish look.
  • Title (TextView): Displays "Calculator" in red text.
  • Two Input Fields (EditText): Allow users to enter two numbers.
  • Four Buttons (Button): Perform addition (+), subtraction (-), multiplication (*), and division (/).
  • Result Display (TextView): Shows the output after a calculation.

Next step? Implement logic in MainActivity.java to perform calculations when buttons are clicked!

<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" android:background="#000" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Calculator" android:textSize="24sp" android:textColor="@color/design_default_color_error" android:layout_margin="20sp" android:gravity="center"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edit1" android:hint="Enter First Value " android:textSize="24sp" android:layout_margin="10sp" android:textColor="@color/design_default_color_error"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/edit2" android:hint="Enter Second Value " android:textSize="24sp" android:layout_margin="10sp" android:textColor="@color/design_default_color_error"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:layout_margin="10dp"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+" android:onClick="Pluse" android:textSize="24sp" android:gravity="center" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:onClick="Minus" android:textSize="24sp" android:gravity="center" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="*" android:onClick="Multiplication" android:textSize="24sp" android:gravity="center" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="/" android:onClick="Division" android:textSize="24sp" android:gravity="center" /> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/text1" android:text="Result" android:textSize="24sp" android:layout_margin="30sp" android:gravity="center"/> </LinearLayout> 
Enter fullscreen mode Exit fullscreen mode

This Java class defines the logic for a simple calculator app in Android. It handles basic arithmetic operations (+, -, *, /) based on user input.

Key Highlights:
UI Elements:
EditText e1, e2; → Input fields for user-entered numbers.
TextView t1; → Displays the result.
Arithmetic Operations:
Addition (Pluse) – Adds two numbers.
Subtraction (Minus) – Subtracts second number from the first.
Multiplication (Multiplication) – Multiplies two numbers.
Division (Division) – Divides first number by second.
EdgeToEdge & Insets Handling: Ensures UI adapts to system bars.
Event Handling: Click events trigger calculations when users press buttons.
💡 Possible Improvements:
✔️ Handle division by zero to prevent app crashes.
✔️ Use try-catch to prevent errors when fields are empty.

Next step? Improve UI and add more features like clear/reset buttons!

package com.example.simplecaluclator; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity extends AppCompatActivity { EditText e1,e2; TextView t1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); e1=this.<EditText>findViewById(R.id.edit1); e2=this.<EditText>findViewById(R.id.edit2); t1=this.<TextView>findViewById(R.id.text1); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); } public void Pluse(View view) { int a,b,c; a=Integer.parseInt(e1.getText().toString()); b=Integer.parseInt(e2.getText().toString()); c=a+b; t1.setText(""+c); } public void Minus(View view) { int a,b,c; a=Integer.parseInt(e1.getText().toString()); b=Integer.parseInt(e2.getText().toString()); c=a-b; t1.setText(""+c); } public void Multiplication(View view) { int a,b,c; a=Integer.parseInt(e1.getText().toString()); b=Integer.parseInt(e2.getText().toString()); c=a*b; t1.setText(""+c); } public void Division(View view) { int a,b,c; a=Integer.parseInt(e1.getText().toString()); b=Integer.parseInt(e2.getText().toString()); c=a/b; t1.setText(""+c); } } 
Enter fullscreen mode Exit fullscreen mode

And This is How it Works;

Image description

During my Android Development Workshop, I explored and built some amazing applications that truly enhanced my skills. Here are my top projects:

✅ 📱 Simple Calculator App – A clean, functional UI with basic arithmetic operations.
✅ 🗣️ Text-to-Speech App – Convert text into speech with a simple click!
✅ 🔀 Intent Application – Seamlessly navigate between activities in Android apps.

These projects gave me hands-on experience with Java & Android Studio, and I loved the process of bringing ideas to life.

👀 More details? I’ll be sharing an in-depth blog soon. Stay tuned!

🔗 Let's connect on LinkedIn! Feel free to DM me to discuss Android development and more.

AndroidDevelopment #AndroidStudio #Java #DevCommunity

Top comments (0)