Last active
March 22, 2018 15:22
-
-
Save devAseemSharma/aaa321d17e8171352aec7dd52538a8b8 to your computer and use it in GitHub Desktop.
Artist Model Class with Parcelable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
YES !
I did this and it works !
Intent intent = getIntent();
Artist value = (Artist) intent.getParcelableExtra("key");
Thank you so much for your help !
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
Before getting your code, I did this (it seems similar):
`public class Artist implements Parcelable {
}`
With your proposition of getIntent().getParcelableExtra("key"); it returns to me this : com.example.android.app.Artist@e54b310
But I don't kown how get data.
getIntent().getParcelableExtra("key").get(
index
) does not work...