Asynchronous APIs in the Android SDK

Asynchronous APIs return a AppCenterFuture object instead of returning the result directly.

You can either call get() on the future object to synchronously wait for the result or provide a callback like this, filling in the respective return types when calling the desired API:

AppCenterFuture<{ReturnType}> future = {AnyAsyncApi}();
future.thenAccept(new AppCenterConsumer<{ReturnType}>() {

    @Override
    public void accept({ReturnType} result) {

        // do something with result, this is called back in UI thread.
    }
});
val future = {AnyAsyncApi}()
future.thenAccept(object : AppCenterConsumer<{ReturnType}> {
    override fun accept(t: {ReturnType}?) {
        // do something with result, this is called back in UI thread.
    }
})

To avoid blocking UI thread that causes slowing down your application, consider using thenAccept with the callback all the time.

On a worker thread you can simply call {AnyAsyncApi}().get().

Callback example:

AppCenter.isEnabled().thenAccept(new AppCenterConsumer<Boolean>() {

    @Override
    public void accept(Boolean enabled) {
        Log.d("MyApp", "AppCenter.isEnabled=" + enabled);
    }
});
AppCenter.isEnabled().thenAccept { enabled -> 
    Log.d("MyApp", "AppCenter.isEnabled=$enabled")
}

Synchronous example:

boolean enabled = AppCenter.isEnabled().get();
val enabled = AppCenter.isEnabled().get()