{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

URLSpanCache

@InternalTextApi
public final class URLSpanCache


This class converts UrlAnnotations to URLSpans, ensuring that the same instance of URLSpan will be returned for every instance of UrlAnnotation. This is required for URLSpans (and any ClickableSpan) to be handled correctly by accessibility services, which require every ClickableSpan to have a stable ID across reads from the accessibility node. A11y services convert these spans to parcelable ones, then look them up later using their ID. Since the ID is a hidden property, the only way to satisfy this constraint is to actually use the same URLSpan instance every time.

See b/253292081.

Summary

Public constructors

Public methods

final @NonNull URLSpan

Public constructors

URLSpanCache

public URLSpanCache()

Public methods

toURLSpan

public final @NonNull URLSpan toURLSpan(@NonNull UrlAnnotation urlAnnotation)