Class IntentContext

java.lang.Object
com.codename1.intents.IntentContext

public final class IntentContext extends Object

The circumstances one invocation runs under. Declare it as the first parameter of a handler to receive it; handlers that do not care about any of this simply leave it out.

@AppIntent(value = "sync_now", title = "Sync now", headless = true)
public static IntentResult sync(IntentContext ctx) {
    while (Backend.hasMore()) {
        if (ctx.isCancelled()) {
            return IntentResult.failed("Sync did not finish in time");
        }
        Backend.syncNextPage();
    }
    return IntentResult.spoken("Everything is up to date");
}
  • Constructor Summary

    Constructors
    Constructor
    Description
    IntentContext(IntentSource source, boolean headless, long deadline)
    Framework entry point.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Framework entry point: marks this invocation abandoned.
    long
    The absolute epoch-millis instant after which this invocation's result is no longer wanted.
    long
    Milliseconds left before the deadline, or 0 once it has passed.
    Where this invocation came from.
    boolean
    True once the framework has stopped waiting for this invocation.
    boolean
    True when the handler is running with no UI on screen.
    Returns a string representation of the object.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • IntentContext

      public IntentContext(IntentSource source, boolean headless, long deadline)

      Framework entry point. Applications receive these, they do not build them.

      Parameters
      • source: where the invocation came from
      • headless: whether the app is running without a visible UI
      • deadline: absolute epoch millis after which the result is discarded
  • Method Details

    • getSource

      public IntentSource getSource()
      Where this invocation came from.
    • isHeadless

      public boolean isHeadless()

      True when the handler is running with no UI on screen.

      This is the flag that decides what the handler is allowed to touch: no Form, no Dialog, nothing that needs a window. See the package documentation for the full contract.

    • getDeadline

      public long getDeadline()

      The absolute epoch-millis instant after which this invocation's result is no longer wanted.

      Matches the shape of com.codename1.background.BackgroundFetch#performBackgroundFetch(long, com.codename1.util.Callback) so the two kinds of background work read the same way.

    • getRemainingTime

      public long getRemainingTime()
      Milliseconds left before the deadline, or 0 once it has passed.
    • isCancelled

      public boolean isCancelled()

      True once the framework has stopped waiting for this invocation.

      Cancellation is cooperative: nothing interrupts a running handler, so a handler doing extended work should check this between steps. Anything it returns after cancellation is discarded, which is why durable work should be committed to storage as it completes rather than only at the end.

    • cancel

      public void cancel()
      Framework entry point: marks this invocation abandoned.
    • 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