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

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

android

Public functions

URLSpan
toURLSpan(urlAnnotation: UrlAnnotation)
android

Public constructors

URLSpanCache

URLSpanCache()

Public functions

toURLSpan

fun toURLSpan(urlAnnotation: UrlAnnotation): URLSpan