Send Object from Activity to Another Activity

Asked 1 years ago, Updated 1 years ago, 90 views

I want to send the object of the customer class to another activity. So I want to show you in other activities What should I do?

public class Customer {

    private String firstName, lastName, Address;
    int Age;

    public Customer(String fname, String lname, int age, String address) {

        firstName = fname;
        lastName = lname;
        Age = age;
        Address = address;
    }

    public String printValues() {

        String data = null;

        data = "First Name :" + firstName + " Last Name :" + lastName
        + + " Age : " + Age + " Address : " + Address;

        return data;
    }
}

android object android-intent

2022-09-22 22:33

1 Answers

You can implement Serializable by inheriting the interface from the Customer class. Then when you send it to the activity, send it to int.putExtra()

You can receive it through getSerializableExtra() from the activities you receive.

// When sending:
intent.putExtra("MyClass", obj);

// When I get it during an activity,
getIntent().getSerializableExtra("MyClass");


2022-09-22 22:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.