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, passing data between activities is a common task when creating interactive applications. Whether you’re sending user input, an object, or a list of items, Android provides built-in methods to transfer this data using Intent. Developers typically use methods like putExtra() and getIntent().getStringExtra() to send and retrieve data. Understanding how to parse and handle this data efficiently is essential for building seamless user experiences in multi-screen applications.

Step 1: Create Two Activities

Assuming you already have two activities:

    • MainActivity.java
    • SecondActivity.java

Step 2: Pass Data Using Intent in MainActivity

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("username", "Aliendroid");
intent.putExtra("age", 25);
startActivity(intent);

You can use putExtra() to send different data types like String, int, boolean, etc.

Step 3: Receive Data in SecondActivity

Intent intent = getIntent();
String username = intent.getStringExtra("username");
int age = intent.getIntExtra("age", 0); // 0 is the default value

Optional: Passing Complex Data (e.g., Objects)

If you want to pass an object, the class should implement Serializable or Parcelable:

import java.io.Serializable;

// Your custom class
public class User implements Serializable {
    String name;
    int age;
    // constructor, getters, etc.

    // Constructor
    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // Getter
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}

Send object:

User user = new User("Aliendroid", 25);
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("userData", user);
startActivity(intent);

Receive object:

User user = (User) getIntent().getSerializableExtra("userData");

Best Practices:

    • Always provide a default value when using getIntExtra, getBooleanExtra, etc.
    • Use constants for keys to avoid typos.
    • Avoid passing large data; use SharedPreferences or Room if needed.