This question already has an answer here:
- How to pass a parcelable object that contains a list of objects? 8 answers
First of all i need to retrieve the list of objects from FileUtils class. There i have the readFromAssets(Contex contex) method which returns the list. So i'm creating object from FileUtils and i'm getting the list.
After that i have tried to implement Parcelable so i can send the list(i dont know if my implementation is OK).
And at the end to send the the list...
public class NoteReaderService extends IntentService{
FileUtils utils = new FileUtils();
List<Note> noteList;
public NoteReaderService(String name) {
super(name);
}
@Override
public void onHandleIntent(Intent intent) {
noteList = utils.readFromAssets(getBaseContext());
MyParcelable obj = new MyParcelable();
obj.setList(noteList);
Intent intentService = new Intent(Constants.BROADCAST_ACTION_INTENT);
intentService.putExtra("key", obj);
sendBroadcast(intentService);
}
public class MyParcelable implements Parcelable {
private List<Note> noteList;
public int describeContents()
{ return 0; }
public void writeToParcel(Parcel out, int flags) {
out.writeList(noteList);
}
public final Parcelable.Creator<MyParcelable> CREATOR = new
Parcelable.Creator<MyParcelable>() {
public MyParcelable createFromParcel(Parcel in) {
return new MyParcelable(in);
}
public MyParcelable[] newArray(int size) {
return new MyParcelable[size];
}
};
private MyParcelable(Parcel in) {
in.readList(noteList, null);
}
public void setList(List<Note> noteList){
this.noteList = noteList;
}
}
But i'm not getting a result from this... My questions are...
- Is my implementation of the Parcelable ok, or i should do it otherwise so i can send my List of objects?
- Am i sending the Parselable object correctly, or i should do it otherwise?
Thanks in advance!