0

I am trying to pass realm object with bundle and I used Parcel library

This is my realm model class. Album.java

@Parcel
public class Album extends RealmObject implements Serializable {
@PrimaryKey
  public String id;
  public String upc;
  public String albumName;
  public String albumArtUrl;
  public String artistName;
  public String genre_id;
  public String genreName;
  public String price;
  public String releaseYear;
  public int explicit;
  public RealmList<Song> songs = new RealmList<>();
}

And this is Song.java.

@Parcel
public class Song extends RealmObject implements Serializable {
  @PrimaryKey
  public String id;
  public String isrc;
  public String songName;
  public String artistName;
  public String album_id;
  public String albumArtUrl;
  public String genre_id;
  public String genreName;
  public String releaseYear;
  public String price;
  public String lyrics;
  public String demo;
  public int explicit;
}

When I try to pass album object in bundle like that,

b.putParcelable("album", Parcels.wrap(album));

I am having that error.

Unable to find generated Parcelable class for com.devhousemyanmar.juketrill.models.Album, verify that your class is configured properly and that the Parcelable class com.devhousemyanmar.juketrill.models.Album$$Parcelable is generated by Parceler.

please help me to solve this.

Min Khant Lu
  • 712
  • 1
  • 9
  • 20

1 Answers1

0

If you check the documentation, it has a section dedicated to using Parceler.

// All classes that extend RealmObject will have a matching RealmProxy class created
// by the annotation processor. Parceler must be made aware of this class. Note that
// the class is not available until the project has been compiled at least once.
@Parcel(implementations = { PersonRealmProxy.class },
        value = Parcel.Serialization.BEAN, // <-- requires getters/setters if set
        analyze = { Person.class })
public class Person extends RealmObject {
    // ...
}

But what's worth noting is that you don't need to specify implementations = {PersonRealmProxy.class} if you use realm.copyFromRealm(song) before passing it to Parcels.wrap(). You'll need to do that anyways if you want to use field values instead of bean serialization strategy, anyways.

Also, you might need a RealmList parceler configuration.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • https://stackoverflow.com/questions/49206007/unable-to-find-generated-parcelable-class?answertab=active#tab-top I tried like u suggested me. But that error still happening to me. Could you please help me to solve this? – Min Khant Lu Mar 10 '18 at 06:41