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

229
Vistas
Listener doesn't work..It seems the Listener is 0

Hey Guys I have this as MainActivity:

public class LoginActivity extends AppCompatActivity {
    public interface LoginListener {
        public void onLoginSuccess();
    }

    public void onLoginSuccess() {
        //logged in and do a few other things
    }
}

And that's my second Activity from where I want to call the method onLoginSuccess() in my MainActivity, as you can see I am doing this with an Listener...

public class FingerprintHandler extends FingerprintManager.AuthenticationCallback {

    private LoginActivity.LoginListener mListener;

    public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
        if (mListener != null) {
            mListener.onLoginSuccess();
        }
        else{
            Toast.makeText((Activity)context, "Listener is 0", Toast.LENGTH_LONG).show();
        }
    }
}

MY problem is that I everytime I try it I get back: "Listener is 0" from my Toast...SO what's wrong?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Check below code for Fingerprint authentication in Android

https://gist.github.com/Evin1-/6aca8421903acca0e927eaefd85bd617

over 4 years ago · Santiago Trujillo Denunciar

0

Extension of my comment above:

You need to register the mListener somehow. A pattern to do this is:

public class MyHandler {

    private LoginListener mListener;

    public MyHandler(LoginListener listener) {
        mListener = listener;
    }

    // ... etc...
}

Where LoginListener is:

public interface LoginListener {
    public void onLoginSuccess();
}

And your activity has:

public MyActivity implements LoginListener {

    // instantiate the handler somewhere, with a reference
    // to "this". "this" refers to the LoginListener interface
    // which is implemented.
    @Override
    public void onCreate(Bundle b) {
        mHandler = new MyHandler(this);
    }

    @Override
    public void onLoginSuccess() {
        Log.i(TAG, "Kewel beanZ");
    }
}

Or, you can define LoginListener as an interface inside the activity if you wish, and instantiate it as:

public LoginListener mListener = new LoginListener() {
    @Override
    public void onLoginSuccess() {
        Log.i(TAG, "Sweet sweet baby beanz");
    }
};

And instead of using this, use mListener, when you create MyHandler.

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