The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

The Autofill API

Many Web browsers, such as Chrome, offer “autofill”. The browser remembers things that you have typed into certain fields, like addresses, and offers to fill those back in when you go to fill in the same form again… or even a different form with similar fields.

Android 8.0 adds autofill capability to Android via the Autofill Framework. Values that users enter into your forms will be remembered and offered again when the user returns to your form, or to other forms that they encounter in other apps on the device. This all happens without any changes to your code… in theory. In practice, you may need some changes to your code.

However, Android itself does not store the form data, nor offer it as suggestions for autofilling in a form. Android is merely serving as a conduit between your app and a third-party autofill service. It is the service that is responsible for determining what could be autofilled in your form and saving prior entries. As with the Assist API, the user can choose an autofill service, and none ship by default with the O Developer Preview. In all likelihood, a Google-branded autofill implementation will be part of the production rollout of Android 8.0, but the user could choose other autofill apps… or perhaps none at all, for privacy reasons.

In this chapter, we will explore the AutoFill API, in terms of:

NOTE: O Developer Preview 2 renamed many of the Autofill Framework classes and methods to make the f in Autofill lowercase. So, for example, AutoFillService became AutofillService. Materials written based on O Developer Preview 1 (blog posts, Stack Overflow answers, etc.) will have a capital F instead.


Understanding this chapter requires that you have read the core chapters of this book.

There are commonalities between autofill and the Assist API, and so this chapter will refer back to that one from time to time.

The Pieces of the Puzzle

Android 8.0 provides a framework for apps with a UI to participate in autofill, by denoting roles that some of those widgets have (e.g., “this is the field for the username”). However, Android itself does not save any user input for later use with autofill, nor does Android itself decide what values are candidates for autofill. Instead, Android delegates that work to a separate autofill service. This works akin to how accessibility services and input method editors work:

Hence, with autofill, there are three pieces: the app with the UI, Android itself, and the autofill service:

Pieces of Autofill
Figure 690: Pieces of Autofill

Here, onFillRequest() and onSuccess() are part of the API for autofill service implementations.

The User Experience

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

What Data Gets Disclosed

The preview of this section was fed to a gremlin, after midnight.

Blocking Autofill as a User

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

Supporting Autofill with Standard Widgets

The preview of this section is being chased by zombies.

Supporting Autofill with Custom Widgets

The preview of this section was last seen in the Bermuda Triangle.

Dealing with Dynamic Changes

The preview of this section left for Hollywood to appear in a reality TV show.

Security Requirements of Autofill Services

The preview of this section is in an invisible, microscopic font.