Typing on the smaller screen of a smartphone or tablet is always time-consuming and frustrating, but this is amplified when applications keep asking for the same information, over and over again. How many times have you typed your email into an app’s login screen? Or entered your credit card number in a payment Activity?

And if you’re a developer, then displaying a form or even a simple login screen, can be a risky business; potentially resulting in users exiting your app, never to return.

However, with the introduction of Android Oreo’s Autofill Framework, data entry is set to become far easier than it’s ever been on the Android platform, and the benefits for developers are two-fold: you can provide a better experience to your users while simultaneously increasing your chances of capturing useful user data.

In this article I’m going to show you how to ensure that all of your app’s “autofillable” fields are ready to receive data from whatever autofill service the user has installed on their device, as well as sharing best practices to ensure you’re making the most out of this Android Oreo feature.

How does autofill work?

The Autofill Framework can detect and store the data types that applications are most likely to request, including passwords, postal addresses and credit card details.

Although the Autofill Framework is an Android 8.0 feature, the user also needs to install a dedicated “autofill service” app that can communicate with this framework. Then, when the Android system detects that the user has entered some new information into an autofillable field, it’ll present a dialog asking whether they want to save this information to their chosen autofill service, at which point it’ll be available to other applications. If they tap ‘Save,’ then the next time the user selects a View that’s requesting the same information, the system will display an autofill picker containing all the relevant datasets stored in the autofill service.

When your app requests information from, or supplys information to an autofill service, it’s known as an autofill client.

Providing hints for autofill

If your app uses standard Views, then by default it should work with any autofill service that uses heuristics to determine the type of data that each View expects. However, not all autofill services use these kind of heuristics; some rely on the View itself to declare the type of data that it expects.

To ensure your app can communicate with the Autofill Framework regardless of the autofill service that the user has installed on their device, you’ll need to add an “android:autofillHints” attribute to every View that’s capable of sending and receiving autofill data.

Let’s take a look at how you’d update a project to provide autofill hints. Create a new project that targets Android Oreo, and then create a basic login screen consisting of two EditTexts that accept a username and a password:

<?xml version=”1.0″ encoding=”utf-8″?>
<android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”com.jessicathornsby.myapplication.MainActivity”>

<TextView
android:layout_width=”wrap_content”
– Source