Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
How to get rid of static variables?

I am having a lot of trouble trying to get rid of a lot of static variables that are present in my app code.

For instance, I have a QueryUtils.JAVA and here I am setting max value to a progress bar on three diferent fragments.

EstatisticasFragment.ef.loadingIndicator.setMax(acumuladorResultados);
ResultadosFragment.rf.loadingIndicatorResultados.setMax(acumuladorResultados);
DeletadosFragment.df.loadingIndicatorDeletados.setMax(acumuladorResultados);

Now, on each Fragment I am doing this:

static EstatisticasFragment ef;
static DeletadosFragment df;
static ResultadosFragment rf;

I know this causes memory leak, but everything I try to do ends up in the same pitfall where non-static variables cannot be referenced from a static context.

Thanks!

--------------------------EDITED--------------------------

Taking a better look, it seems to me that QueryUtils is meant to be all static, but how can I make the interaction between Activity QueryUtils (Static) and Fragment (Non Static)?

Thanks!

--------------------------EDITED--------------------------

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you can make a new class with all the variables you are using as static variables and create getter setters for the variables.Now instantiate your class object in the class where you want to use the variables and set the variables using setters function

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda