I have the following Classes:
public class Creature implements Serializable {
protected String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
// Rest of the methods and variables
}
Player Class extends Creature:
public class Player extends Creature implements Serializable {
// Class code
}
I am passing an instance of Player
from one activity to another using Intents
:
// Activity A, passing the object
Intent charActivity= new Intent(this, CharacterActivity.class);
charActivity.putExtra("Player", player);
startActivity(goToCharacterActivity);
// Activity B, grabbing the object
Player player = (Player) getIntent().getSerializableExtra("Player");
Now if I do something like player.setName("Hello");
in activity B the "original" object name doesn't update, the new name will be valid only in this current activity, because I only have a local "copy" of the object. How do I go around this if I must use Serializable?