# Android integration flow

> [!WARNING]
> **Deprecated:** Smart Lock for Passwords is deprecated. To ensure the continued security and usability of your app, [migrate to
> Credential Manager](https://developer.android.com/training/sign-in/passkeys/) today. Credential Manager supports passkey, password, and federated identity authentication (such as Sign-in with Google), stronger security, and a more consistent user experience.

To integrate Smart Lock for Passwords into your Android app, you must add calls
to the [Credentials API](https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/package-summary)
to your app's start-up and sign-in flow. The following diagram shows the flow of
a typical Android app that uses Smart Lock for Passwords.

While there are many ways to successfully integrate Smart Lock for Passwords,
and the specifics of an integration depend on the structure and user experience
of the app, the following flow is recommended for most apps. Apps that use this
flow have these user experience advantages:

- Existing users of your service that have a single credential saved are immediately signed in, and they will go directly to the signed-in view when they open the app.
- Users that have multiple credentials saved or that have disabled automatic sign-in need to respond to only one dialog before they go to the app's signed-in view.
- Users that have no saved credentials or haven't signed up yet can pick their name and email with a single tap and be intelligently sent to either the sign-in or sign-up view, with this information pre-filled.
- When users sign out, the app ensures they are not automatically signed back in.

[![Diagram of Smart Lock sign-in flow](https://developers.google.com/static/identity/smartlock-passwords/android/images/smartlock-passwords-flow.png)](https://developers.google.com/static/identity/smartlock-passwords/android/images/smartlock-passwords-flow.png)

### Retrieve credentials

1. When the app starts, if no user is already signed in, call `CredentialsClient.request()`.
2. If the `Task` is successful, get the user's credentials with `getResult().getCredential()` and use them to sign in.
3. If the `Task` fails and the exception is an instance of `ResolvableApiException` and `getStatusCode()` returns `RESOLUTION_REQUIRED`, user input is required to pick a credential. Call `startResolutionForResult()` to prompt the user to select a saved account, then call `getParcelableExtra(Credential.EXTRA_KEY)` to get the user's credentials and use them to sign in.

   > [!IMPORTANT]
   > If signing in with the retrieved credentials fails because the password is incorrect or the account doesn't exist, delete the credentials from Smart Lock with `CredentialsClient.delete()`.

### Save credentials

4. If the `Task` fails with an `ApiException` and
   `getStatusCode()` returns `SIGN_IN_REQUIRED`, the
   user has no saved credentials and must sign in or sign up manually using
   your current sign-in or sign-up flow. After the user successfully
   completes sign in, you can provide an opportunity for the user to save
   their credentials for future retrieval (step 5).

   You can help the user sign in or sign up faster and more
   easily by retrieving sign-in hints, such as the user's email address. The
   user can select the hint and skip typing their credentials. If your app
   requires users to sign in, you might choose to retrieve hints immediately
   after the initial credentials request fails (otherwise, you can wait until
   the user starts the sign-in or sign-up flow).
   1. Call `CredentialsClient.getHintPickerIntent()` and start the intent to prompt the user to select an account, then call `getParcelableExtra(Credential.EXTRA_KEY)` to get the sign-in hint.
   2. If the user ID of the hint matches an existing user, pre-fill the sign-in form with it and let the user enter the password to sign in.
   3. If the user ID of the hint doesn't match an existing user, pre-fill the sign-up form with the user's ID and name, and let the user create a new account.
5. After the user successfully signs in or creates an account, save the user
   ID and password with `CredentialsClient.save()`.

   If the user signed in with a federated identity provider such as Google
   Sign-In, create the `Credential` object with the user's email
   address as the ID and specify the identity provider with
   `setAccountType`.

### Sign out

6. When the user signs out, call `CredentialsClient.disableAutoSignIn()` to prevent the user from being immediately signed back in. Disabling auto-sign-in also enables users to switch between accounts easily---for example, between work and personal accounts, or between accounts on shared devices---without having to re-enter their sign-in information.

Ready to integrate Smart Lock for Passwords into your app?
[Get started](https://developers.google.com/identity/smartlock-passwords/android/get-started).