# Class AppEntity

java.lang.Object
com.codename1.intents.AppEntity

public final class AppEntity extends Object

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.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AppEntity(String type, String id)`
  Creates an entity of a declared type.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `AppEntity`
  `addKeywords(String... words)`
  Extra words a search should match this entity on, beyond its title and subtitle.
  `String`
  `getId()`
  The stable identifier of this instance.
  `EncodedImage`
  `getImage()`
  The thumbnail, or null.
  `List<String>`
  `getKeywords()`
  The keywords added so far.
  `String`
  `getSubtitle()`
  The secondary line, or null.
  `String`
  `getTitle()`
  The primary line shown by a picker or a search result.
  `String`
  `getType()`
  The entity type id.
  `AppEntity`
  `setImage(EncodedImage image)`
  Sets the thumbnail.
  `AppEntity`
  `setSubtitle(String subtitle)`
  Sets the secondary line.
  `AppEntity`
  `setTitle(String title)`
  Sets the primary line.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### AppEntity

    public AppEntity(String type, String id)

    Creates an entity of a declared type.

    ###### Parameters

    - `type`: the entity type id, matching an `IntentEntity` declaration. It may not contain `:`, which separates the type from the id in the identifier the platforms store.
    - `id`: 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()
    The entity type id.

  - ### getId

    public String getId()
    The stable identifier of this instance.

  - ### getTitle

    public String getTitle()
    The primary line shown by a picker or a search result.

  - ### setTitle

    public AppEntity setTitle(String title)

    Sets the primary line. Required for anything indexed -- an entity with no title has nothing to show in a search result.

    ###### Parameters

    - `title`: the display title

    ###### Returns

    this entity, for chaining

  - ### getSubtitle

    public String getSubtitle()
    The secondary line, or null.

  - ### setSubtitle

    public AppEntity setSubtitle(String subtitle)

    Sets the secondary line.

    ###### Parameters

    - `subtitle`: the display subtitle

    ###### Returns

    this entity, for chaining

  - ### getImage

    public EncodedImage getImage()
    The thumbnail, or null.

  - ### 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

    - `image`: the thumbnail

    ###### Returns

    this entity, for chaining

  - ### addKeywords

    public AppEntity addKeywords(String... words)

    Extra words a search should match this entity on, beyond its title and subtitle.

    ###### Parameters

    - `words`: the keywords to add; null is ignored

    ###### Returns

    this entity, for chaining

  - ### getKeywords

    public List<String> getKeywords()
    The keywords added so far.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    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())
    Overrides:
      `toString` in class `Object`