Programatically close Auth0 LockActivity for android

  android, auth0, auth0-lock, java

I am using the Auth0 Lock framework for Android and recently ran into an issue.

Our requirement is to show a biometric authentication prompt to the user, above the Auth0 Lock screen (if enabled). When I get the credentials after login via Auth0 Lock screen, it closes the Lock activity and so I need to replicate the same scenario if someone used their biometric auth. Once the user successfully authenticates via biometrics, I am using the SecureCredentialsManager to get the renewed access token. So how can I close the lock activity after I get the successful authentication via biometrics? Below is the code snippet for the behavior.

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Constants.lockActivity = this;

    String audience = this.getString(R.string.com_auth0_audience);
    String scope = this.getString(R.string.com_auth0_scope);

    final Lock.Builder builder = Lock.newBuilder(sessionManager.getAccount(), sessionManager.lockCallback());
    builder.withAudience(audience);
    builder.withScope(scope);
    builder.allowSignUp(false);
    builder.withUsernameStyle(UsernameStyle.EMAIL);
    builder.hideMainScreenTitle(true);

    Constants.lock = builder.build(this);

    this.startActivity(Constants.lock.newIntent(this));
}

@Override
protected void onStart() {
    super.onStart();
    if (sharedPreferencesManager.getIsBiometricsEnabled()) {
        Intent biometricIntent = new Intent(this, BiometricActivity.class);
        this.startActivity(biometricIntent);
    }
}

I am new to android development and would really appreciate it if someone can point me in the right direction.

Source: Android Questions

LEAVE A COMMENT