Donovant Donovant - 2 months ago 23
Android Question

I can't read property of an object passed between two android activities by using Parcelable

This is the class that implements Parcelable:

public class MyUser implements Parcelable{

private String userName;
private String password;

MyUser(String u, String p){
userName = u;
password = p;

private MyUser(Parcel p){
Log.i("Parcel p", p.readString());

userName = p.readString();
password = p.readString();

// Getters
String getUserName(){ return userName; }
String getPassword(){ return password; }

// Setters
void setUserName(String u){ userName = u; }
void setPassword(String p){ password = p; }

public int describeContents() {
return hashCode();

public void writeToParcel(Parcel dest, int flags) {

public static final Parcelable.Creator<MyUser> CREATOR = new Parcelable.Creator<MyUser>() {

public MyUser createFromParcel(Parcel source) {
return new MyUser(source);

public MyUser[] newArray(int size) {
return new MyUser[0];


In FirstActivity:

username = (EditText) findViewById(;

Intent secondStep = new Intent(this, SecondActivity.class);
mu = new MyUser(

secondStep.putExtra("MyUser", mu);
Log.i(100 +": "+ mu.getUserName(), mu.getPassword());

In SecondActivity:

Intent intent = getIntent();
Log.i("Second Activity", ": +intent.getExtras().getParcelable("MyUser"));

My Log is:

I/Second Activity: :

wheras I was aspecting to read the username written in the


The object and the property are two different things:

    MyUser mu = intent.getExtras().getParcelable("MyUser")
    Log.i("Second Activity", ": +mu.getUserName());