Skip to content

Blocking and Non-blocking APIs

Most of Backendless APIs for Android and Java are available in synchronous and asynchronous formats. The difference in the method signatures is the asynchronous methods accept the AsyncCallback<T> argument:

package com.backendless.async.callback;

import com.backendless.exceptions.BackendlessFault;

public interface AsyncCallback<T>
{
  void handleResponse( T response );
  void handleFault( BackendlessFault fault );
}

The handleResponse( T response ) method is called when a response for the asynchronous operation is available. If operation results in an error, it is delivered to the handleFault method. See the "Error Handling" section for additional information on how to process errors.

Important

Android applications cannot use synchronous APIs on the main UI thread. The reason for this is the main thread does not allow blocking calls. Since the API requests perform network-based communication, the naturally block. As a result, when using the Backendless APIs make sure to use the asynchronous version of the methods, or create a new thread and use the synchronous API in it:

new Thread(new Runnable() {
        public void run() {
            // synchronous backendless API call here:
            Backendless.XXXX()
        }
    }).start();