java – Is it bad to use a singleton for storing large arraylists?-ThrowExceptions

Exception or error:

Before i used putParcelableArrayListExtra to send the arraylist between activities, but when my arraylist got to big i got E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!.

Now i’m using a Singleton for storing my arraylist, but everywhere i look it says it’s bad coding to use a singleton pattern.

Why should i not use a singleton and what are my other options for storing big arraylists?

private static Main mainInstance = null;

    public static synchronized Main getInstance(){
        if (mainInstance == null){
            mainInstance = new Main();
        }
        return  mainInstance;
    }

    public void setSongList(ArrayList<Song> songList){
        this.songList = songList;
    }

    public ArrayList<Song> getSongList() {
        return songList;
    }
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *