public final class IntentContext

  1. Object
  2. IntentContext

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");
}

Constructors

public IntentContext(IntentSource source, boolean headless, long deadline)Framework entry point.

Methods

public IntentSource getSource()Where this invocation came from.
public boolean isHeadless()True when the handler is running with no UI on screen.
public long getDeadline()The absolute epoch-millis instant after which this invocation’s result is no longer wanted.
public long getRemainingTime()Milliseconds left before the deadline, or 0 once it has passed.
public boolean isCancelled()True once the framework has stopped waiting for this invocation.
public void cancel()Framework entry point: marks this invocation abandoned.
public String toString()Returns a string representation of the object.

Inherited methods

Constructor details

IntentContext

public IntentContext(IntentSource source, boolean headless, long deadline)
Framework entry point. Applications receive these, they do not build them.

Parameters

source IntentSource
where the invocation came from
headless boolean
whether the app is running without a visible UI
deadline long
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()
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())