Class DynamicIntent

java.lang.Object
com.codename1.intents.DynamicIntent

public final class DynamicIntent extends Object

A named parameterization of an intent your application already declares -- "reorder my usual", "call Mum" -- built from data only known at runtime.

Map<String, Object> usual = new HashMap<String, Object>();
usual.put("shop", "shop-7");
usual.put("size", "large");
Intents.registerDynamicIntent(new DynamicIntent("usual_coffee", "order_coffee",
        "Order my usual").bind(usual));
Why it must name a base intent

It runs by running the intent it names, with the bound values filled in. It cannot introduce a new capability: the native catalogue is compiled into the app, so a genuinely new verb could never reach the platform, and a runtime API that appeared to add one would work in the simulator and silently do nothing on a device.

Binding to a base intent is also what makes it invokable at all -- there is a handler to run, which is the whole point of registering it.

  • Constructor Details

    • DynamicIntent

      public DynamicIntent(String id, String baseIntentId, String title)

      Creates a parameterization.

      Parameters
      • id: the id this parameterization is known by; must not collide with a declared intent
      • baseIntentId: the declared intent that actually runs
      • title: the name shown to the user
  • Method Details

    • bind

      public DynamicIntent bind(Map<String,Object> params)

      Binds values for the base intent's parameters. Anything supplied at invocation time wins, so a bound value is a default rather than a lock.

      Parameters
      • params: the values to bind
      Returns

      this parameterization, for chaining

    • bind

      public DynamicIntent bind(String name, Object value)

      Binds one value.

      Parameters
      • name: the parameter name
      • value: the value to bind
      Returns

      this parameterization, for chaining

    • getId

      public String getId()
    • getBaseIntentId

      public String getBaseIntentId()
      The declared intent this runs.
    • getTitle

      public String getTitle()
    • getBoundParameters

      public Map<String,Object> getBoundParameters()
      The bound values, never null.
    • 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