Skip to content

Most visited

Recently visited

navigation

SaveInfo

public final class SaveInfo
extends Object implements Parcelable

java.lang.Object
   ↳ android.service.autofill.SaveInfo


Information used to indicate that an AutofillService is interested on saving the user-inputed data for future use, through a onSaveRequest(SaveRequest, SaveCallback) call.

A SaveInfo is always associated with a FillResponse, and it contains at least two pieces of information:

  1. The type(s) of user data (like password or credit card info) that would be saved.
  2. The minimum set of views (represented by their AutofillId) that need to be changed to trigger a save request.

Typically, the SaveInfo contains the same ids as the Dataset:

   new FillResponse.Builder()
       .addDataset(new Dataset.Builder()
           .setValue(id1, AutofillValue.forText("homer"), createPresentation("homer")) // username
           .setValue(id2, AutofillValue.forText("D'OH!"), createPresentation("password for homer")) // password
           .build())
       .setSaveInfo(new SaveInfo.Builder(
           SaveInfo.SAVE_DATA_TYPE_USERNAME | SaveInfo.SAVE_DATA_TYPE_PASSWORD,
           new AutofillId[] { id1, id2 }).build())
       .build();
 

The save type flags are used to display the appropriate strings in the save UI affordance. You can pass multiple values, but try to keep it short if possible. In the above example, just SaveInfo.SAVE_DATA_TYPE_PASSWORD would be enough.

There might be cases where the AutofillService knows how to fill the screen, but the user has no data for it. In that case, the FillResponse should contain just the SaveInfo, but no Datasets:

   new FillResponse.Builder()
       .setSaveInfo(new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_PASSWORD,
           new AutofillId[] { id1, id2 }).build())
       .build();
 

There might be cases where the user data in the AutofillService is enough to populate some fields but not all, and the service would still be interested on saving the other fields. In that case, the service could set the setOptionalIds(AutofillId[]) as well:

   new FillResponse.Builder()
       .addDataset(new Dataset.Builder()
           .setValue(id1, AutofillValue.forText("742 Evergreen Terrace"),
               createPresentation("742 Evergreen Terrace")) // street
           .setValue(id2, AutofillValue.forText("Springfield"),
               createPresentation("Springfield")) // city
           .build())
       .setSaveInfo(new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_ADDRESS,
           new AutofillId[] { id1, id2 }) // street and  city
           .setOptionalIds(new AutofillId[] { id3, id4 }) // state and zipcode
           .build())
       .build();
 

The onSaveRequest(SaveRequest, SaveCallback) can be triggered after any of the following events:

But it is only triggered when all conditions below are met:

  • The SaveInfo associated with the FillResponse is not null.
  • The AutofillValues of all required views (as set by the requiredIds passed to the SaveInfo.Builder constructor are not empty.
  • The AutofillValue of at least one view (be it required or optional) has changed (i.e., it's neither the same value passed in a Dataset, nor the initial value presented in the view).
  • There is no Dataset in the last FillResponse that completely matches the screen state (i.e., all required and optional fields in the dataset have the same value as the fields in the screen).
  • The user explicitly tapped the UI affordance asking to save data for autofill.

The service can also customize some aspects of the save UI affordance:

Summary

Nested classes

class SaveInfo.Builder

A builder for SaveInfo objects. 

Constants

int FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE

Usually onSaveRequest(SaveRequest, SaveCallback) is called once the Activity finishes.

int NEGATIVE_BUTTON_STYLE_CANCEL

Style for the negative button of the save UI to cancel the save operation.

int NEGATIVE_BUTTON_STYLE_REJECT

Style for the negative button of the save UI to reject the save operation.

int SAVE_DATA_TYPE_ADDRESS

Type used on when the FillResponse represents a physical address (such as street, city, state, etc).

int SAVE_DATA_TYPE_CREDIT_CARD

Type used when the FillResponse represents a credit card.

int SAVE_DATA_TYPE_EMAIL_ADDRESS

Type used when the FillResponse represents just an email address, without a password.

int SAVE_DATA_TYPE_GENERIC

Type used when the service can save the contents of a screen, but cannot describe what the content is for.

int SAVE_DATA_TYPE_PASSWORD

Type used when the FillResponse represents user credentials that have a password.

int SAVE_DATA_TYPE_USERNAME

Type used when the FillResponse represents just an username, without a password.

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<SaveInfo> CREATOR

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel parcel, int flags)

Flatten this object in to a Parcel.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Constants

FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE

added in API level 26
int FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE

Usually onSaveRequest(SaveRequest, SaveCallback) is called once the Activity finishes. If this flag is set it is called once all saved views become invisible.

Constant Value: 1 (0x00000001)

NEGATIVE_BUTTON_STYLE_CANCEL

added in API level 26
int NEGATIVE_BUTTON_STYLE_CANCEL

Style for the negative button of the save UI to cancel the save operation. In this case, the user tapping the negative button signals that they would prefer to not save the filled content.

Constant Value: 0 (0x00000000)

NEGATIVE_BUTTON_STYLE_REJECT

added in API level 26
int NEGATIVE_BUTTON_STYLE_REJECT

Style for the negative button of the save UI to reject the save operation. This could be useful if the user needs to opt-in your service and the save prompt is an advertisement of the potential value you can add to the user. In this case, the user tapping the negative button sends a strong signal that the feature may not be useful and you may consider some backoff strategy.

Constant Value: 1 (0x00000001)

SAVE_DATA_TYPE_ADDRESS

added in API level 26
int SAVE_DATA_TYPE_ADDRESS

Type used on when the FillResponse represents a physical address (such as street, city, state, etc).

Constant Value: 2 (0x00000002)

SAVE_DATA_TYPE_CREDIT_CARD

added in API level 26
int SAVE_DATA_TYPE_CREDIT_CARD

Type used when the FillResponse represents a credit card.

Constant Value: 4 (0x00000004)

SAVE_DATA_TYPE_EMAIL_ADDRESS

added in API level 26
int SAVE_DATA_TYPE_EMAIL_ADDRESS

Type used when the FillResponse represents just an email address, without a password.

Constant Value: 16 (0x00000010)

SAVE_DATA_TYPE_GENERIC

added in API level 26
int SAVE_DATA_TYPE_GENERIC

Type used when the service can save the contents of a screen, but cannot describe what the content is for.

Constant Value: 0 (0x00000000)

SAVE_DATA_TYPE_PASSWORD

added in API level 26
int SAVE_DATA_TYPE_PASSWORD

Type used when the FillResponse represents user credentials that have a password.

Constant Value: 1 (0x00000001)

SAVE_DATA_TYPE_USERNAME

added in API level 26
int SAVE_DATA_TYPE_USERNAME

Type used when the FillResponse represents just an username, without a password.

Constant Value: 8 (0x00000008)

Fields

CREATOR

added in API level 26
Creator<SaveInfo> CREATOR

Public methods

describeContents

added in API level 26
int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

toString

added in API level 26
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

writeToParcel

added in API level 26
void writeToParcel (Parcel parcel, 
                int flags)

Flatten this object in to a Parcel.

Parameters
parcel Parcel: The Parcel in which the object should be written.

flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)