mardi 5 avril 2016

What is the efficient way to pass objects and/or list of objects between activities?

I am new to android and learning good design patters in one of my classes. I am developing an app as part of my project but I am running into some design problems and trying to figure out what is a good pattern to follow.

I have the following classes

public class Playlist {
  ArrayList<Song> songs = new ArrayList<Song>();
  //..getters and setters and song to list

  }

public class Song {
  private String name;
  private String artist;
  private String File;
  //Getters and setters

}

Throughout the app I will have an ArrayList of all the created playlist and an ArrayList of all the songs available.

The app eventually will download a JSON object and make an instance of a Song class for that object.

I have been looking into way to keep the list of playlist objects and list of song objects available through all the activities and I have found the following solutions:

  1. making a Gson and saving it to sharedPref file (this does not seem like a good idea since I will be saving and writing constantly.)

  2. I have also read about using sqllite. But I don't see the point of it since I will be getting most songs as a JSON object and making a song instance with that object.

  3. I implemented playlist as parceable to be able to pass the list through an intent but this does not seem like the best way since I will have to update the shared pref every time there is a change.

Can anyone point me in the right direction which way to follow or if making a singleton for the lists seem like the most efficient way. (Global singletons so android wouldn't destroy the objects onDestroy())

Thanks

Aucun commentaire:

Enregistrer un commentaire