Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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 answers
Answer question

0

Check below code for Fingerprint authentication in Android

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

over 4 years ago · Santiago Trujillo Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!