I'm making a game, and I need to move a custom Object. To do that, I'm using a Parcelable to move data.
However, I'm having problems moving the data, and I don't know why.
This is Parcelable class:
public class Character implements Parcelable {
public static int day;
public static int now_food;
public static int now_water;
public static int use_food;
public static int use_water;
public static int health;
public static String name;
public static char status; // d = 병걸림, n = 정상
public static char status_live; //w = 죽음 l = 생존
public static String status_water ; // t = 목마름 v = 매우 목마름
public static String status_food ; // h = 배고픔 v = 매우 배고픔
public Character() {
}
public Character(Parcel in) {
}
public Character(int use_food, int use_water, int health, String name, char status) {
this.status = status;
this.use_food = use_food;
this.use_water = use_water;
this.health = health;
this.name = name;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(use_food);
dest.writeInt(use_water);
dest.writeInt(health);
dest.writeString(name);
}
public void readFromParcel(Parcel in) {
use_food = in.readInt();
use_water = in.readInt();
health = in.readInt();
name = in.readString();
}
public static final Creator<Character> CREATOR = new Creator<Character>() {
@Override
public Character createFromParcel(Parcel in) {
return new Character(in);
}
@Override
public Character[] newArray(int size) {
return new Character[size];
}
};
@Override
public int describeContents() {
return 0;
}
}
Here's my main code:
character1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), Character1_Activity.class);
intent.putExtra("ch1info", ch1);
startActivity(intent);
}
});
I move this object with button's click event.
Finally, this is the Activity that wants to get object.
Bundle bundle = getIntent().getExtras();
final Character ch1 = bundle.getParcelable("ch1info");
TextView get_water = (TextView) findViewById(R.id.water_stat);
get_water.setText(ch1.Check_water(ch1));
Why doesn't my code work, and how can I fix it?