Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda