0

I'm having troubles with getting content from getParcelableArrayList.

I have data model class that extends parcelable

@DatabaseTable(tableName = "note")
public class Log implements Parcelable {

@DatabaseField(id = true, index = true)
UUID id;

@DatabaseField
String title;

@DatabaseField
String description;

public Log() {
}

@Override
public int describeContents() {
    return 0;
}

public Log(Parcel in) {
    this.title = in.readString();
    this.description = in.readString();
}

@Override
public void writeToParcel(Parcel out, int flags) {
    out.writeString(title);
    out.writeString(description);
}

public void readFromParcel(Parcel in){
    title = in.readString();
    description = in.readString();
}

public static final Parcelable.Creator<Log> CREATOR = new Parcelable.Creator<Log>(){
    public Log createFromParcel(Parcel in){
        return new FoodLog(in);
    }
    public Log[] newArray(int size){
        return new FoodLog[size];
    }
};

And I want make feature for editing entry in database. I'm sending data from activity one to activity two via bundle like this

Activity one:

Intent intent = new Intent(LogList.this, AddLogActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("list", new ArrayList<>(mLog));
intent.putExtras(bundle);
startActivity(intent);

Receiving bundle via intent in Activity two:

Intent mIntent = getIntent();
if (mIntent != null) {
    Bundle bundle = mIntent.getExtras();
    if (bundle != null) {
        mLogParcel = bundle.getParcelableArrayList("list");
    }
}

So, my question is how to get data from passed arraylist in Activity two?

I have data saved inArrayList<Log> mLogParcel;, and I tried using readFromParcel on mLogParcel, but without positive results. How to get data based on data model in this case?

Thanks a lot!

George Mulligan
  • 11,813
  • 6
  • 37
  • 50
robigroza
  • 559
  • 1
  • 5
  • 22

0 Answers0