0

I have one fragment and ,when i click fragment button one base activity will open,base activity contain three fragments in tab format.according to activity tab button click fragment will change . Now I am calling an api in base activity and store response values in a temporary class

public class ListTempStorage {
    private static final ListTempStorage myInstance = new ListTempStorage();
    private List<MyListOne> listOne = new ArrayList<>();
    private List<MyListOne> listTwo = new ArrayList<>();

    private ListTempStorage() {
    }

    public static ListTempStorage getInstance() {
        return myInstance;
    }

    public List<MyListOne> getListOne() {
        return listOne;
    }

    public void setList(List<MyListOne> list) {
        this.listOne = listOne;
    }

        public void setListTwo(List<MyListOne> listTwo) {
        this.listTwo = listTwo;
    }

    public List<MyListOne> getListTwo() {
        return listTwo;
    }
}

and in my fragments I am calling this list and populating these list values.

if (clicked == "butOne") {
    List<MyListOne> listOne = ListTempStorage.getInstance().getListOne();
    if (listOne != null && listOne.size() > 0) {
        populateLayout(listOne);
    }
}
if (clicked == "butTwo") {
    List<MyListOne> listTwo = ListTempStorage.getInstance().getListTwo();
    if (listTwo != null && listTwo.size() > 0) {
         populateLayout(listTwo);
    }
}

The problem is first time its populating list, but if I change fragments according to my filter conditions some time I am getting old list values, its not updating. I think some memory leak happen there.

0 Answers0