Photo by Bozhin Karaivanov on Unsplash
In today’s competitive mobile landscape, a seamless user experience is no longer a luxury, it’s a necessity. Every interaction a user has with your app is an opportunity to either build trust and loyalty or create friction that leads to uninstalls. One of the most common points of friction is the dreaded process of filling out forms. Whether it’s for signing up, logging in, or making a purchase, manually typing information is tedious, error-prone, and a major cause of user drop-off.
This is where the Android Autofill framework comes in as a powerful tool to streamline these interactions. By intelligently and securely filling in user data with a single tap, Autofill transforms a cumbersome process into a frictionless one. For users, it means less typing and fewer mistakes. For developers, it translates to higher conversion rates, improved data accuracy, and a more polished, professional application. This article will dive into how you can leverage the Autofill framework in your own Android apps, covering everything from the foundational concepts in traditional XML layouts to the latest best practices in Jetpack Compose.

Sample image from official docs.
What is Autofill?
Autofill is an Android feature (Android 8.0+) that lets a user’s chosen autofill service, such as a password manager, securely provide stored data to your app’s input fields while the system coordinates the interaction. It reduces typing and mistakes, and can fill credentials, addresses, and payment details. Autofill also complements modern sign-in flows like Credential Manager and passkeys.
Why implement Autofill?
Implementing Autofill is crucial for a great modern app, significantly enhancing the User Experience (UX) and driving conversion. With the new Compose text system, all it takes is setting the content type semantic property on your TextField.
This minimal effort delivers outsized returns:
Boost Conversions: By enabling one-tap form completion, Autofill reduces friction and drop-offs during critical user flows like sign-in and checkout.
Improve Accuracy: It minimizes the need for manual typing, effectively reducing errors and typos in addresses, emails, and credentials.
Strengthen Security: The framework integrates with trusted Autofill Services and modern flows like **Credential Manager and passkeys**, allowing the service to securely suggest and save credentials.
Enhance Input: Setting the property also benefits accessibility and ensures the correct on-screen keyboard (like the numeric keypad for a zip code) appears instantly.

Sample image from official docs.
What can be autofilled?
Common categories include:
Credentials: Username, password, new username/password, SMS one-time codes.
Contact info: Full name, first/middle/last name, prefix/suffix, email, phone.
Address: Country, region/state, city, street, postal code.
Payments: Credit card number, CVC, expiration month/year/day/date.
Personal data: Gender, birth date (day/month/year/full).
For the complete, up-to-date list of content types, refer to the Android Autofill hints documentation (`AUTOFILL_HINT_*`) and the corresponding Compose content types in the official docs.
Implementation: Integrating Autofill
Views/XML Implementation
In the XML system, the complexity lies in both tagging the field and the framework’s internal management (which can introduce performance overhead).
You set the Autofill Hint on the EditTexteither in the XML layout or programmatically.
Via XML Attribute (Recommended):
<EditText android:id="@+id/username_input" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Username" android:autofillHints="username" />
Programmatic Setting (Manual):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val password = findViewById<EditText>(R.id.manual_fill_set)
password.setAutofillHints(View.AUTOFILL_HINT_NAME)
}
For more precise control, especially when dealing with custom Views or scenarios where a View might not be automatically recognized, you can use the android:importantForAutoFill attribute. The default value is auto, which allows the system to determine importance. However, you can explicitly include a View using yesor exclude it using no.

Jetpack Compose Implementation
The new Compose text system drastically simplifies implementation. The framework automatically handles View bounds and focus changes, a refactoring that led to a massive text to text performance improvement.
Set the Content Type
To enable Autofill, you only need to use the semantics modifier to set the expected ContentType. This single line replaces all the complexity required in the View system:
TextField(
value = username,
onValueChange = { username = it },
label = { Text("Username") },
modifier = Modifier
.semantics {
contentType = ContentType.Username
}
)

The Crucial Commit Step
The Autofill framework shows a “Save for autofill?” dialog when the autofill context is finished, signaling that the user has completed a transaction with new or updated data. This context finish can be triggered both implicitly (automatically) and explicitly (manually).
How Saving is Triggered
Saving is often triggered automatically when the Autofill Context finishes, which typically happens when the user successfully navigates away from the screen or the Activity finishes. This implicit save works for both Views/XML and Compose, where the Compose system tries to determine navigation for you.
However, you must explicitly call AutofillManager.commit()in scenarios where the context does not finish automatically:
Fragment/Single-Activity Navigation: If your app uses a single activityto host multiple screens via Fragments or Composable screens, the Activity never finishes. You must call commit() to explicitly finish the context.
Multi-Step Forms: For forms spanning multiple screens, you must only call commit() after the user completes the final step to ensure the full, correlated data set is saved.
Explicit Commit Implementation
You commit the autofill session to prompt the service to save the data. If you need to discard any pending data without saving it, you can call AutofillManager.cancel().
In Views/XML, you must retrieve the AutoFillManager using the context and call AutofillManager.commit(), typically guarding the call with an Android version check:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Get the AutofillManager instance
val autofillManager = context.getSystemService(AutofillManager::class.java)
// Commit the autofill session
autofillManager.commit()
}
In Jetpack Compose, the process is streamlined using the local Composition: you retrieve the manager using LocalAutoFillManager.current and then call commit() on the submit button’s click handler:
val autofillManager = LocalAutofillManager.current
Button(onClick = { autofillManager?.commit() }) { Text("Submit") }
How to Test Autofill
Testing your Autofill implementation is crucial to ensure a smooth user experience. This involves a two-part process: first setting up an autofill service on your test device, and then verifying that both the data filling and data saving functionalities work as expected.
To begin, you’ll need to enable an autofill service. First, you need to enable an autofill service on your test device or emulator.
- Navigate to your device’s Settings app.
- Use the search bar to find “Autofill service”. This is typically found under sections like “Passwords & accounts” or “System.”
- Select an active service from the list. “Autofill with Google” is a standard option available on most devices. Alternatively, you can use a third-party password manager.
- Make sure the service has data you can use for testing (e.g., a saved address or a set of login credentials).
Once the service is active, you can proceed to test your app. Launch your application and navigate to the form you want to test. When you tap on an input field that you’ve configured for autofill, the service should present a UI overlay with relevant saved information. Selecting an entry from this overlay should correctly populate the corresponding fields in your form. This verifies the data filling flow.

Job Offers
Conclusion
Android Autofill has evolved into a seamless, high-performance system that enhances both user experience and developer productivity. In traditional XML Views, developers needed to manually configure autofill hints and manage the lifecycle of the AutofillManager. With Jetpack Compose, the process is now dramatically simplified—setting a single contentType property automatically enables secure, efficient autofill integration with minimal overhead.
Compose also introduces intelligent automatic saving when users navigate away from a screen, while still allowing explicit commits for advanced cases such as multi-step forms or single-activity apps. By adopting these modern practices, developers can deliver smoother sign-in, checkout, and form-filling experiences with minimal code and maximum performance.
Appreciate you taking the time to read this!
I share more thoughts on mobile development and software engineering on LinkedIn.
Follow along, stay inspired, and see you in the next blog! 💪
This article was previously published on proandroiddev.com



