I want to send user define object from one activity to another in android application.
I have created user class object and send this user object to my second activity from first activity.
I want to send user define object from one activity to another in android application.
I have created user class object and send this user object to my second activity from first activity.
Implement your class with Serializable interface. Then pass the object using
intent.putExtra("MyClass", obj);
and retrieve object by calling
getIntent().getSerializableExtra("MyClass");
Make sure your User
class implements Parcelable
.
public class User implements Parcelable {
...........
...............
}
Send User
object to SecondActivity
as below:
User userObject = new User();
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("user_data", userObject);
startActivity(intent);
Retrieving the User
object in SecondActivity
.
User user = (User) getIntent().getParcelableExtra("user_data");
Here is good Tutorial about using Parcelable
.
Hope this will help~