public class JRoutine extends JRoutine
Context.startService(android.content.Intent) method. Normally the service
will stay active only during a routine invocation. In fact, it is responsibility of the caller
to ensure that the started invocations have completed or have been aborted when the relative
context (for example the activity) is destroyed, so to avoid the leak of IPC connections.Parcel.writeValue(Object) method. Be aware though, that issues may arise
when employing Serializable objects on some OS versions, so, it is advisable to
use Parcelable objects instead.
For example, in order to get a resource from the network, needed to fill an activity UI:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity_layout);
final Routine<URI, MyResource> routine =
JRoutine.on(serviceFrom(this), targetInvocation(LoadResourceUri.class))
.buildRoutine();
routine.asyncCall(RESOURCE_URI)
.passTo(new TemplateOutputConsumer<MyResource>() {
@Override
public void onError(@Nullable final Throwable error) {
displayError(error);
}
@Override
public void onOutput(final MyResource resource) {
displayResource(resource);
}
});
}
Created by davide-maestroni on 01/08/2015.| Constructor and Description |
|---|
JRoutine() |
| Modifier and Type | Method and Description |
|---|---|
static ServiceObjectRoutineBuilder |
on(ServiceContext context,
ContextInvocationTarget target)
Returns a builder of routines running in a service based on the specified context, wrapping
the specified target object.
In order to customize the object creation, the caller must employ an implementation of a FactoryContext as the invocation
service. |
static <IN,OUT> ServiceRoutineBuilder<IN,OUT> |
on(ServiceContext context,
InvocationFactoryTarget<IN,OUT> target)
Returns a builder of routines running in a service based on the specified context.
In order to customize the invocation creation, the caller must override the method getInvocationFactory(InvocationFactoryTarget) of the routine service. |
@Nonnull public static ServiceObjectRoutineBuilder on(@Nonnull ServiceContext context, @Nonnull ContextInvocationTarget target)
FactoryContext as the invocation
service.
Note that the built routine results will be dispatched into the configured looper, thus,
waiting for the outputs on the very same looper thread, immediately after its invocation,
will result in a deadlock.context - the service context.target - the invocation target.@Nonnull public static <IN,OUT> ServiceRoutineBuilder<IN,OUT> on(@Nonnull ServiceContext context, @Nonnull InvocationFactoryTarget<IN,OUT> target)
getInvocationFactory(InvocationFactoryTarget) of the routine service.
Note that the built routine results will be dispatched into the configured looper, thus,
waiting for the outputs on the very same looper thread, immediately after its invocation,
will result in a deadlock.IN - the input data type.OUT - the output data type.context - the service context.target - the invocation target.