Class 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");
}
-
Constructor Summary
ConstructorsConstructorDescriptionIntentContext(IntentSource source, boolean headless, long deadline) Framework entry point. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Framework entry point: marks this invocation abandoned.longThe absolute epoch-millis instant after which this invocation's result is no longer wanted.longMilliseconds left before the deadline, or 0 once it has passed.Where this invocation came from.booleanTrue once the framework has stopped waiting for this invocation.booleanTrue when the handler is running with no UI on screen.toString()Returns a string representation of the object.
-
Constructor Details
-
IntentContext
Framework entry point. Applications receive these, they do not build them.
Parameters
source: where the invocation came fromheadless: whether the app is running without a visible UIdeadline: absolute epoch millis after which the result is discarded
-
-
Method Details
-
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, noDialog, 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
Description copied from class:ObjectReturns 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())
-