I’ve got a class which contains a getter and setter for the variable “artist”:
Class:
public void setArtist(String artist) {
this.artist = artist;
}
public String getArtist() {
return artist;
}
I’d like to call setArtist from an activity like so:
Activity 1:
Playlist.setArtist(someString)
But eclipse tells me I need to change setArtist to static. The whole point of me using setters was to avoid having any static references. Am I doing something wrong, or is there another way to accomplish this?
It entirely depends on where and when you want your object. You could do something like this:
Activity 1:
Activity 2:
You then have a reference to your Artist in the second Activity:
Watch what you are serialising as you cannot serialize certain objects.
Another way to go it would be to have a class that extends Application and keep a reference in there, then you could retrieve it from any Activity context.