Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Asynchronous Execution of Operations

Asynchronous Execution of Operations

You can execute Backend Services Android SDK operations asynchronously. Asynchronous calls are handled by an abstract callback class.

You will notice that each facade has a method that allows asynchronous execution. Asynchronous calls are handled by an abstract callback class RequestResultCallbackAction<T> which has only method invoke() which accepts RequestResult as parameter.

executeAsync(new RequestResultCallbackAction<ArrayList<Activity>>() {
        @Override
        public void invoke(RequestResult<ArrayList<Activity>> requestResult) {
            if (requestResult.getSuccess()) {
                for (Activity activity : requestResult.getValue()) {
                    System.out.println(activity.toString());
                }
            } else {
                System.out.println(requestResult.getError().toString());
            }
        }
});

As you can see both classes RequestResultCallbackAction<T> and RequestResult<T> are generic which allows to put some "syntax sugar" in the code.

You can call executeAsync() method without parameters in cases when you do not need to handle the result (or it is expected to be null). The best example for this is the LogoutFacade which generally cannot get wrong. ​

app.workwith().authentication().logout().executeAsync();

Be aware that by default all asynchronous calls are executed as daemon threads which means that execution will be interrupted when parent application stops. In order to override this behavior just use the overload method executeAsync(RequestResultCallbackAction<T>, executeAsDaemon).

app.workwith().authentication().logout().executeAsync(null, false);
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.