Issue
To give you a little context, I try to pass my 'match' object from the GamesBottomActivity to the GameActionsActivity. My Match model is implementing Parcelable and I have well implemented the required methods from the interface. Here it is.
public class Match implements Parcelable {
// Attributes
private int id;
private String local ;
private int score_local ;
private String visitor;
private int score_visitor ;
// private DateTime date;
private String arena;
// Constructor
public Match(JSONObject recipesJson) throws JSONException {
this.id = recipesJson.getInt("id");
this.local = recipesJson.getString("local");
this.score_local = recipesJson.getInt("score_local");
this.visitor = recipesJson.getString("visitor");
this.score_visitor = recipesJson.getInt("score_visitor");
//this.date = recipesJson.getString("date");
this.arena = recipesJson.getString("arena");
}
// Constructor ++
public Match(int id, String local, String visitor, int score_local, int score_visitor, String arena) {
this.id = id;
this.local = local;
this.score_local = score_local;
this.visitor = visitor;
this.score_visitor = score_visitor;
this.arena = arena;
}
// Getters
public int getId() {
return id;
}
public String getLocal() {
return local;
}
public String getVisitor() {
return visitor;
}
public String getArena() {
return arena;
}
public int getLocalScore() { return score_local;}
public int getVisitorScore() { return score_visitor;}
/*
public Date getDate() {
return date;
}
*/
// Update function
protected Match(Parcel in) {
id = in.readInt();
local = in.readString();
visitor = in.readString();
arena = in.readString();
//date = in.readString();
score_local = in.readInt();
score_visitor = in.readInt();
}
public static final Creator<Match> CREATOR = new Creator<Match>() {
@Override
public Match createFromParcel(Parcel in) {
return new Match(in);
}
@Override
public Match[] newArray(int size) {
return new Match[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(id);
parcel.writeString(local);
parcel.writeInt(score_local);
parcel.writeString(visitor);
parcel.writeInt(score_visitor);
parcel.writeString(arena);
//parcel.writeInt(date);
}
@Override
public String toString() {
return "{ " +
"id='" + id + '\'' +
", arena='" + arena + '\'' +
", local ='" + local + '\'' +
", local score ='" + score_local + '\'' +
", visitor ='" + visitor +'\''+
", visitor score ='" + score_local+'}';
}
}
Code I'm using to send my data to add the 'match' object in the Extra to start the next activity
Code I'm using to receive my data from the extras, in the second activity
The logs from Logcat show me at the end that the object I passed (match) has good values (on the sending side), but then, the values are wrecked (on the receiving side). It's interesting to note that the ID and the Local values are OK, but not the other ones.
Anybody would have an idea of why the object gets wrecked in the middle ?
I tried, as you saw in previous screenshots, to use the Log.d logging function with Logcat, to see the object is OK before sending it, and not OK after receiving it.
Solution
To those who wants the answer of how I resolved that : In my match model class, the order of the variables when we manipule the parcel is important.
I had to set the same order of the variables, between my constructor and the parcel function : Contructor Parcel function
With that, it's working now !
Answered By - Jmx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.