Skip to content
(deprecated) Decoupled executor — the easiest & type-safe way to run code in Android service
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Decouplex (deprecated)

Decoupled executor — the easiest & type-safe way to run code in Android service

An alternative

In many cases you can use presenters which survive lifecycle changes, like in Moxy.

This library is abandoned and deprecated.

Include via Gradle

Just Decouplex

Download Methods count

compile 'net.aquadc.decouplex:decouplex:0.0.3'

DecouplexRetrofit — adapter for Retrofit


compile 'net.aquadc.decouplex:decouplexRetrofit:0.0.3'

compile 'net.aquadc.decouplex:decouplexRetrofit:0.0.3:release@aar' — this strange thing will be fixed in next release

To do in next releases

  • Add something like @OnFinish with finally semantics;
  • Support DecouplexBatchRequest.retry & document DecouplexBatch;
  • Develop REMOTE DeliveryStrategy to use implementation that runs in another process;
  • Static factory with default parameter values to use in Kotlin without Builder;
  • Eager validation;
  • less ProGuard rules.

New in 0.0.3

  • Support nullable @OnResult and @OnError methods' arguments by means of @DcxNullable annotation;
  • Allow some methods to be called without result or error delivery by means of @DcxDelivery annotation;
  • If an exception has raised in @OnResult method, delivering InvocationTargetException to @OnError;
  • If an exception has raised in @OnError method, delivering two exception to fallback handler.

Now it's OK for @OnResult and @OnError methods to declare (throws) and throw exceptions — you can catch them all inside your fallback error handler and send them to Crashlytics.

Since 0.0.2

  • DeliveryStrategy: a way to transfer arguments from UI to Service. The only one is available for now — DeliveryStrategies.LOCAL. Method arguments and return value will now be transferred out of Bundle and there's no need for them to be Parcelable;
  • Adapters' API changed: they aren't dependent on Bundle any more;
  • A bug that caused a crash on SocketTimeoutException delivery was fixed (actually, any exception delivery would be failed if this exception provides no message but @OnError method requires it).

Since 0.0.1

  • Arguments and return values delivery;
  • Wildcard result/error handlers (e. g. @OnResult("list*") works with all methods which names start with "list");
  • @Debounce(delay).


You can write your code like this:

class SampleFragment extends DecouplexFragment {

    private GitHubService gitHubService;

    public void onAttach(Context context) {
        if (gitHubService == null) {
            // configure Retrofit
            GitHubService gitHubRetrofitService =
                    new Retrofit.Builder()

            // configure Decouplex
            gitHubService = DecouplexBuilder
                            GitHubService.class, gitHubRetrofitService, getClass());
    // OnClick
    public void myGitHub() {
    protected void onReposListed(List<Repo> repos) {
    // some code
    // setting OnClickListeners
    // enableUi & formatRepos methods
    // and other presenter logic

Of course, GitHubService in this example is a Retrofit2-compatible interface:

public interface GitHubService {
    Call<List<Repo>> listRepos(@Path("user") String user);

You have to add service in manifest:

<service android:name="net.aquadc.decouplex.DecouplexService" />

When your class does not extend DecouplexActivity or DecouplexFragment, you can register & unregister BroadcastReceiver wherever you need: in onCreate/onDestroy, onStart/onStop, or onResume/onPause.

class MyClass extends Fragment or Activity {

    private DecouplexReceiver decouplexReceiver;

    protected void onStart() {
        if (decouplexReceiver == null)
            decouplexReceiver = new DecouplexReceiver(this);

    protected void onStop() {
You can’t perform that action at this time.