I'm sending an object of my custom class which implements Serializable:
public class MyObject extends ParseObject implements Serializable {
private static final long serialVersionUID = 1L;
public MyObject() {
}
public String getTitle() {
return getString("title");
}
public void setTitle(String title) {
put("title", title);
}
public ParseFile getParseFile() {
return getParseFile("file");
}
public void setParseFile(ParseFile file) {
put("file", file);
}
}
The class contains atm one string and one ParseFile.
I'm trying to pass an object from one Activity to another.
private void editMyObject(MyObject myObject) {
Intent intent = new Intent(AActivity.this, BActivity.class);
intent.putExtra("MyObject", myObject);
Toast.makeText(getApplicationContext(), "OUT: "+myObject.getTitle(), Toast.LENGTH_SHORT).show(); // here i get the content, proper string
startActivity(intent);
}
And in 'receiver' activity:
protected void onCreate(Bundle savedInstanceState) {
...
Intent intent = getIntent();
myObject = (MyObject)intent.getSerializableExtra("MyObject");
if (myObject != null) {
editText.setText(myObject.getTitle());
}
Toast.makeText(getApplicationContext(), "IN: "+myObject.getTitle(), Toast.LENGTH_SHORT).show(); // here is null
}
What am i doing wrong..? I followed another questions on SOF but that didn't help ;) BTW: No, ParseFile is class from Parse developers
I guess It should be Something like this ParsObject implements Serializable because according the Topic about Serializable if the Super class is not serializable then the state of the instance is not maintained. So try to make The ParseObject class Serializable and see the result
Try Something Like this
public class MyObject implements Serializable {
private ParseObject parseObject;
public MyObject() {
parseObject = new ParseObject();
}
public String getTitle() {
return parseObject.getString("title");
}
public void setTitle(String title) {
parseObject.put("title", title);
}
public ParseFile getParseFile() {
return parseObject.getParseFile("file");
}
public void setParseFile(ParseFile file) {
parseObject.put("file", file);
}
private void writeObject(java.io.ObjectOutputStream stream)
throws IOException {
stream.writeObject(parseObject);
}
private void readObject(java.io.ObjectInputStream stream)
throws IOException, ClassNotFoundException {
parseObject = (ParseObject) stream.readObject();
}
}