public final class AppEntity
- Object
- AppEntity
The platform-facing view of one of your app’s nouns – an order, a playlist, a saved route.
This is what an entity looks like after it has left your code. Your own
class stays your own class; the build reads its EntityId / EntityTitle /
EntitySubtitle / EntityImage members and generates the adapter that
produces one of these. You construct AppEntity directly only when indexing
content that has no annotated class behind it.
The field set is small because it is the intersection of what every platform entity display model actually has: something to identify it by, something to show, something to show underneath, a picture, and words to match a search against.
The id is a promise
Ids outlive the process. Spotlight keeps indexed items and the system keeps donated shortcuts, both of them holding your id, so an id has to mean the same thing after an app update as it did before. An id derived from a list position or a content hash will silently start resolving to the wrong object and nothing will report an error.
Constructors
public AppEntity(String type, String id) | Creates an entity of a declared type. |
Methods
public String getType() | The entity type id. |
public String getId() | The stable identifier of this instance. |
public String getTitle() | The primary line shown by a picker or a search result. |
public AppEntity setTitle(String title) | Sets the primary line. |
public String getSubtitle() | The secondary line, or null. |
public AppEntity setSubtitle(String subtitle) | Sets the secondary line. |
public EncodedImage getImage() | The thumbnail, or null. |
public AppEntity setImage(EncodedImage image) | Sets the thumbnail. |
public AppEntity addKeywords(String... words) | Extra words a search should match this entity on, beyond its title and subtitle. |
public List<String> getKeywords() | The keywords added so far. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
AppEntity
public AppEntity(String type, String id)Parameters
typeString- the entity type id, matching an
IntentEntitydeclaration. It may not contain:, which separates the type from the id in the identifier the platforms store. idString- the stable identifier of this instance. Colons are fine here: the uid splits at the first one, so everything after it is the id.
Method details
getType
public String getType()getId
public String getId()getTitle
public String getTitle()setTitle
public AppEntity setTitle(String title)Parameters
titleString- the display title
Returns
getSubtitle
public String getSubtitle()setSubtitle
public AppEntity setSubtitle(String subtitle)Parameters
subtitleString- the display subtitle
Returns
getImage
public EncodedImage getImage()setImage
public AppEntity setImage(EncodedImage image)Sets the thumbnail.
An EncodedImage rather than an Image because the bytes cross to the
platform as-is. Handing over an image that still has to be rasterized
would mean encoding it here, which on a device is exactly the kind of
work that looks instantaneous in the simulator and stalls on hardware.
Parameters
imageEncodedImage- the thumbnail
Returns
addKeywords
public AppEntity addKeywords(String... words)Parameters
wordsString...- the keywords to add; null is ignored
Returns
getKeywords
public List<String> getKeywords()toString
public String toString()