Skip to content

Instantly share code, notes, and snippets.

@devAseemSharma
Last active March 22, 2018 15:22
Show Gist options
  • Save devAseemSharma/aaa321d17e8171352aec7dd52538a8b8 to your computer and use it in GitHub Desktop.
Save devAseemSharma/aaa321d17e8171352aec7dd52538a8b8 to your computer and use it in GitHub Desktop.
Artist Model Class with Parcelable
public class Artist implements Parcelable
{
private String artistName;
private String albumName;
private String imgAlbum;
private String artistTitle;
public final static Parcelable.Creator<Artist> CREATOR = new Creator<Artist>() {
@SuppressWarnings({
"unchecked"
})
public Artist createFromParcel(Parcel in) {
return new Artist(in);
}
public Artist[] newArray(int size) {
return (new Artist[size]);
}
}
;
protected Artist(Parcel in) {
this.artistName = ((String) in.readValue((String.class.getClassLoader())));
this.albumName = ((String) in.readValue((String.class.getClassLoader())));
this.imgAlbum = ((String) in.readValue((String.class.getClassLoader())));
this.artistTitle = ((String) in.readValue((String.class.getClassLoader())));
}
public Artist() {
}
public String getArtistName() {
return artistName;
}
public void setArtistName(String artistName) {
this.artistName = artistName;
}
public String getAlbumName() {
return albumName;
}
public void setAlbumName(String albumName) {
this.albumName = albumName;
}
public String getImgAlbum() {
return imgAlbum;
}
public void setImgAlbum(String imgAlbum) {
this.imgAlbum = imgAlbum;
}
public String getArtistTitle() {
return artistTitle;
}
public void setArtistTitle(String artistTitle) {
this.artistTitle = artistTitle;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(artistName);
dest.writeValue(albumName);
dest.writeValue(imgAlbum);
dest.writeValue(artistTitle);
}
public int describeContents() {
return 0;
}
}
Changes you need to do in your MainActivity and ShowTracksActivity classes:
In MainActivity.class :
Artist artist = artists.get(position);
intent.putExtra ("key", artist);
In ShowTracksActivity.class :
getIntent().getParcelableExtra("key");
@devAseemSharma
Copy link
Author

devAseemSharma commented Mar 22, 2018

You're welcome. And you figured out the problem great work for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment