free web tracker
Course Content
Java Programming Basics for Android
Learn the basics of Java programming for Android app development using Android Studio. This guide covers key concepts like variables, loops, and classes to help you start building your first Android apps with confidence. Perfect for beginners!
0/10
User Interaction and App Logic
Learn how to make your app respond to users! This section covers handling clicks, getting input, showing messages, switching screens, and saving simple data. A perfect start to build interactive Android apps with real logic.
0/10
Advanced Layouts and Components
Learn to build modern Android UIs using advanced layouts like RecyclerView, CardView, TabLayout, and more. This section helps beginners create beautiful, interactive, and user-friendly app interfaces step by step.
0/10
Media and Resources
Learn how to manage media and resources in Android Studio. This section covers adding audio, images, video, using drawables, custom fonts, and handling runtime permissions—essential for building rich, engaging Android applications.
0/4
Mastering Java Android Development – Beginner

In Android development, navigating between different screens or “activities” is a common task. This can be done using Intents in Java. Intents are messaging objects used to request an action from another app component.

This guide will show you how to move from one activity to another using explicit intents in Android Studio with Java.

Step 1: Create a Second Activity

    1. Right-click on the java package > New > Activity > Empty Activity.

    1. Name it SecondActivity.

    1. Click Finish.

Android Studio will automatically generate:

    • SecondActivity.java
    • activity_second.xml

Step 2: Design Layouts

activity_main.xml

Add a Button:

<Button
    android:id="@+id/btnNavigate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Go to Second Activity"
    android:layout_centerInParent="true"/>

activity_main.xml

Add a TextView:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Welcome to Second Activity"
    android:textSize="18sp"
    android:layout_centerInParent="true"/>

Step 3: Add Navigation Logic in Java

MainActivity.java

package com.example.intentexampleapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    Button btnNavigate;

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

        btnNavigate = findViewById(R.id.btnNavigate);

        btnNavigate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Create an explicit Intent to start SecondActivity
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(intent);
            }
        });
    }
}

SecondActivity.java

package com.example.intentexampleapp;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class SecondActivity extends AppCompatActivity {

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

Step 4: Declare the Second Activity in AndroidManifest

Open AndroidManifest.xml and add this line inside the <application> tag:

<activity android:name=".SecondActivity"></activity>

Conclusion

You’ve successfully created an app that navigates between two activities using an explicit intent in Java. This is one of the foundational skills in Android app development. You can now build on this knowledge by passing data between activities or using implicit intents.