public final class IntentContext
- Object
- 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)Parameters
sourceIntentSource- where the invocation came from
headlessboolean- whether the app is running without a visible UI
deadlinelong- absolute epoch millis after which the result is discarded
Method details
getSource
public IntentSource getSource()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()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()toString
public String toString()