Static ArrayList returns size 0 when I try to retrieve it in an activity

0

I have this class:

abstract public class ListaEstaticaDeErros {
private static ArrayList<DescritorDeErro> listErros = new ArrayList<DescritorDeErro>();
private static boolean fimSinc = false;
private static int municipio = 0;

public static boolean getFimSinc(){
    return fimSinc;
}

public static int getMunicipio(){
    return municipio;
}

public static void setMunicipio(int i){
    municipio = i;
}

public static void setFimSinc(boolean b){
    fimSinc = b;
}

public static void setListErros(ArrayList<DescritorDeErro> list){
    listErros = list;
}

public static void addRegListErros(DescritorDeErro obj){
    listErros.add(obj);
}

public static ArrayList<DescritorDeErro> getListErros(){
    return listErros;
}

}

Activity function that I try to retrieve and show the size of the list:

public void montarResultados(){
        Log.e("Teste-esus", String.valueOf(ListaEstaticaDeErros.getListErros().size()));
        Bundle bundle = getIntent().getExtras();
        ArrayList<DescritorDeErro> lst = bundle.getParcelableArrayList("lista");
        int mun = bundle.getInt("municipio");
        String usuario = bundle.getString("usuario");
        if(lst.size() > 0) {
            new ChargeList().execute(lst, mun, usuario);
        }else{
            txtVInfo.setText("Nenhum erro capturado ate este momento de sincronização.");
        }
        if(bundle.getBoolean("fim_sinc")) {
            txtEmail.setVisibility(View.VISIBLE);
        }else{
            txtEmail.setVisibility(View.INVISIBLE);
        }
    }

And within an activity I need to retrieve this list and it always returns me 0, that is without any element, but if I get it in another class that is not an activity I get it without problems, so the solution I did was get it in another class and send via intent to the activity I need, but I would like to take it directly from the activity so I can implement what I need.

    
asked by anonymous 02.08.2018 / 15:59

2 answers

0

You can do this:

    public class ListaEstaticaDeErros {
    private ArrayList<DescritorDeErro> listErros = new ArrayList<DescritorDeErro>();
    private boolean fimSinc = false;
    private int municipio = 0;

    private static ListaEstaticaDeErros instance;

    public static ListaEstaticaDeErros getInstance() {
        if (instance == null) {
            instance = new ListaEstaticaDeErros()
        }

        return instance;
    }

    public  boolean getFimSinc(){
        retmSinc;
    }

    public  int getMunicipio(){
        retnicipio;
    }

    public  void setMunicipio(int i){
        mun = i;
    }

    public  void setFimSinc(boolean b){
        fim b;
    }

    public  void setListErros(ArrayList<DescritorDeErro> list){
        lis = list;
    }

    public  void addRegListErros(DescritorDeErro obj){
        lis.add(obj);
    }

    public  ArrayList<DescritorDeErro> getListErros(){
        return listErros;
    }
}
    
02.08.2018 / 18:33
0

Create an interface as below, which will be able to retrieve the values of listErros.

public interfaceStatisticalElement List {

static ArrayList listErros = new ArrayList ();

... }

    
03.08.2018 / 17:00