Search code examples
androidfingerprintandroid-fingerprint-api

Enable fingerprint service again after successful authentication


I have implemented login using finger print authentication and it works well.

Below is the Activity that calls the authenticate method:

FingerPrintActivity

onCreate(){
  … //Code to initialize the fingerprint manager

  FingerprintHandler fingerprintHandler = new FingerprintHandler(this);
  fingerprintHandler.startAuthentication(fingerprintManagerCompat, null);
}

FingerPrintHandler

 @Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    updateLoginUi("Successfully verified!", true);

}


private void updateLoginUi(String authenticationMessage, boolean result){
 if(result){
  context.startActivity(…)
 }
}

After successfully verifying the fingerprint, I launch the MainActivity,

however, on pressing the back button to go back to the fingerprint activity, I am unable to use the service. What do I need to activate or trigger in order to validate the fingerprint again?


Solution

  • You could move

      FingerprintHandler fingerprintHandler = new FingerprintHandler(this);
      fingerprintHandler.startAuthentication(fingerprintManagerCompat, null);
    

    from onCreate() to onResume().

    In this case it would start authentication everytime you go into the activity, if that is what you want.