[Deprecated] Sexy way to execute async/background tasks on Android

Related tags

Utility groundy
Overview

Groundy library for Android

@Deprecated

Unfortunatenly this library is no longer maintained, we encourage you to use other widely supported solutions like RxJava.

Groundy

Groundy is a fun, sexy way to do background work on your Android app; it's specially useful for running tasks that must be executed even if your activities/fragments are destroyed. It allows you to receive notifications from the background task directly to your activity or any object.

It is useful for several scenarios like executing calls to external services (e.g. RESTful web services), download and/or process files, encoding audio/video and any kind of task that could block the main thread.

Basic usage

Create a subclass of GroundyTask:

public class ExampleTask extends GroundyTask {
  @Override
  protected TaskResult doInBackground() {
    // you can send parameters to the task using a Bundle (optional)
    String exampleParam = getStringArg("arg_name");

    // lots of code

    // return a TaskResult depending on the success of your task
    // and optionally pass some results back
    return succeeded().add("the_result", "some result");
  }
}

Whenever you want to execute the task, just do this:

// this is usually performed from within an Activity
Groundy.create(ExampleTask.class)
    .callback(callbackObj)        // required if you want to get notified of your task lifecycle
    .arg("arg_name", "foo")       // optional
    .queueUsing(YourActivity.this);

You will get results in your callback object(s) (in the main thread):

@OnSuccess(ExampleTask.class)
public void onSuccess(@Param("the_result") String result) {
  // do something with the result
}

Do not forget to add GroundyService to the AndroidManifest.xml file:

<service android:name="com.telly.groundy.GroundyService"/>

Extending callback system

There are some already defined onCallback annotations: @OnSuccess, @OnFailed, @OnCancel, @OnProgress and @OnStart, but you can also create your own callback types like:

@OnCallback(task = ChuckTask.class, name = "kick")
public void onChuckNorrisAttack(@Param("target") String target) {
  Toast.makeText(this, "Chuck Norris kicked your " + target, Toast.LENGTH_SHORT).show();
}

Take a look at the custom callbacks example for details on this.

Integration

In order to use this library from you Android project using Maven your pom should look like this:

<dependency>
  <groupId>com.telly</groupId>
  <artifactId>groundy</artifactId>
  <version>(insert latest version)</version>
</dependency>

<!-- enables groundy JSR-269 processor which makes everything up to 5 times faster -->
<dependency>
  <groupId>com.telly</groupId>
  <artifactId>groundy-compiler</artifactId>
  <version>(insert latest version)</version>
</dependency>

For Gradle projects use:

compile 'com.telly:groundy:(insert latest version)'
provided 'com.telly:groundy-compiler:(insert latest version)'

Note: provided dependencies are supported by android gradle plugin v0.8 or later.

At this point latest version is 1.5.

Proguard

If you are using proguard, please add these rules

-keepattributes *Annotation*

-keepclassmembers,allowobfuscation class * {
    @com.telly.groundy.annotations.* *;
    <init>();
}

-keepnames class com.telly.groundy.generated.*
-keep class com.telly.groundy.generated.*
-keep class com.telly.groundy.ResultProxy
-keepnames class * extends com.telly.groundy.ResultProxy
-keep class * extends com.telly.groundy.GroundyTask
You might also like...
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.

Secure-preferences - Deprecated Please use EncryptedSharedPreferences from androidx.security in preferenced to secure-preference. (There are no active

Android library which makes it  easy to handle the different obstacles while calling an API (Web Service) in Android App.
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector

Android Gesture Detectors Framework Introduction Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as

Use Android as Rubber Ducky against another Android device
Use Android as Rubber Ducky against another Android device

Use Android as Rubber Ducky against another Android device

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

A util for setting status bar style on Android App.
A util for setting status bar style on Android App.

StatusBarUtil A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4). 中文版点我 Sample Download StatusBarUtil-Demo Chang

A logger with a small, extensible API which provides utility on top of Android's normal Log class.
A logger with a small, extensible API which provides utility on top of Android's normal Log class.

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class. I copy this class into all the little apps

Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

Disk LRU Cache A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key m

a simple cache for android and java

ASimpleCache ASimpleCache 是一个为android制定的 轻量级的 开源缓存框架。轻量到只有一个java文件(由十几个类精简而来)。 1、它可以缓存什么东西? 普通的字符串、JsonObject、JsonArray、Bitmap、Drawable、序列化的java对象,和 b

Comments
  • Follow redirects even when the response was not empty

    Follow redirects even when the response was not empty

    The existance and/or size content length header field is not really indicative of a redirect. The content length header may be empty for a non-redirected request as well as there may be some content returned for a redirected request.

    With this PR, only the existance of the location header field is used to determine if the request is being redirected.

    opened by mkraemer 2
  • Fixing unmarshaling crash when restoring result receiver

    Fixing unmarshaling crash when restoring result receiver

    There are two possible causes for this error, both plausible and fixed by this commit:

    1. Since I was using ResultReceiver.class.getClassLoader() instead of CallbacksReceiver.class.getClassLoader(), there is a chance that Parcelable instance was using the default class loader instead of the app one.
    2. Parcelable implementation might fail if the object being restored was null. In order to avoid such cases, we are not saving the result receiver if it's null (using a boolean flag control such cases).

    @eveliotc Since I was not able to reproduce this on the phone, and Genymotion is still not working for me, I'd really appreciate if you could test and see whether the bug was actually fixed.

    opened by casidiablo 1
[] Easy async loading for Android's ListView/GridView

NOTE: Smoothie's API is not final yet. Although the library is fairly funcional, this is still beta-quality code. Do not rely on it for production cod

Lucas Rocha 988 Dec 22, 2022
[Deprecated] AKA VectorDrawableCompat: A 7+ backport of VectorDrawable

###@Deprecated Unfortunatenly this library is no longer maintained, we encourage you to use first party VectorDrawableCompat coming soon to support li

Telly 658 Oct 9, 2022
A small library which will save you from writing the same intent creation code again and again for the most simple tasks

Android Intents A small library which will save you from writing the same intent creation code again and again for the most simple tasks. I found myse

MarvinLabs 420 Nov 20, 2022
Utility for detecting and notifying when your Android app goes background / becomes foreground

Foredroid Utility for detecting and notifying when your Android app goes background / becomes foreground. API-level 14+. Usage: Initialise Foreground

Steve Liles 151 Nov 29, 2022
:iphone: [Android Library] Get device information in a super easy way.

EasyDeviceInfo Android library to get device information in a super easy way. The library is built for simplicity and approachability. It not only eli

Nishant Srivastava 1.7k Dec 22, 2022
A compose friendly way to deal with in app updates on android

In-App update compose A way to make in app updates in compose How to include in your project The library is available via MavenCentral: allprojects {

Stefan Wärting 25 Dec 31, 2022
learn RxJava in new way!

RxLab amazing tool to learn ReactiveX Programming with animation, schedulers and time project on GitHub. this is an open source Android application wr

Anas Altair 70 Oct 21, 2022
TSBattery a new way to save your battery avoid cancer apps hacker it.

TSBattery TSBattery a new way to save your battery avoid cancer apps hacker it. TSBattery 是一个旨在使 QQ、TIM 变得更省电的开源 Xposed 模块 Get startted 此模块支持原生 Xposed

Fankesyooni 375 Jan 2, 2023
Keep data as a linked list on disk. A alternative way to reduce redundant operation for DiskLruCache

DiskLinkedList Keep data as a linked list on disk. An alternative way to reduce redundant operation for DiskLruCache Use-case Android have build-in Di

Cuong V. Nguyen 6 Oct 29, 2021
This is a easy way to publish MQTT message and receive MQTT message

SMQ-CLIENT This is a easy way to publish MQTT message and receive MQTT message This is provider a spring stater for quick use Recive message form the

SUDA 1 Apr 25, 2022