Futuroid

General

Category
Free
Tag
Background Processing
License
N/A
Registered
Dec 8, 2014
Favorites
1
Link
https://github.com/clemp6r/futuroid
See also
Task Queue
Stitch
Bolts
AndroidChannel
Android-Task

Additional

Language
Java
Version
v0.3.0 (May 17, 2014)
Created
Mar 15, 2014
Updated
Feb 22, 2016 (Retired)
Owner
Clément Plantier (clemp6r)
Contributors
Ravindra Kumar (ravidsrk)
Clément Plantier (clemp6r)
2
Activity
Badge
Generate
Download
Source code

Futuroid - Android library for asynchronous tasks

Futuroid is an Android library that allows running asynchronous tasks and attaching callbacks thanks to a convenient syntax. It offers an alternative to the Android AsyncTask class.

Features

  • Future-based API (similar to Guava's ListenableFutures, Scala/Akka Futures, Javascript promises...)
  • Allows registering callbacks to be run on the Android UI/main thread
  • Provides a default ExecutorService (fixed thread pool with 5 threads) that can be replaced by a custom one
  • Each task can be run on the default ExecutorService or on a custom one
  • Allows task chaining (monad-style)

Sample code

Image download asynchronous service:

    public class DownloadService {
        
        /**
         * Downloads an image asynchronously.
         */
        public Future<Bitmap> downloadImage(String url) {
            return Async.submit(new Callable<Bitmap>() {
                @Override
                public Bitmap call() {
                    Bitmap bitmap;
                    
                    // HTTP request goes here...
                    
                    return bitmap;
                }
            });
        }
    }

Client code:

    // download an image from a URL
    imageService.downloadImage(url).addCallback(new FutureCallback<Bitmap>() {
        @Override
        public void onSuccess(Bitmap bitmap) {
            // display the image
            imageView.setImageBitmap(bitmap);
        }

        @Override
        public void onFailure(Throwable t) {
            Log.e(TAG, "Unable to download image", t);
        }
    });

Adding Futuroid to your project

Futuroid is available on the Maven Central Repository.

Maven-based configuration:

    <dependency>
        <groupId>com.github.clemp6r.futuroid</groupId>
        <artifactId>futuroid</artifactId>
        <version>1.0.0</version>
    </dependency>

Gradle-based configuration:

    dependencies {
        compile 'com.github.clemp6r.futuroid:futuroid:1.0.0'
    }

Links

API documentation