How To Cancel Async.executeAsync

I am reading variables from an Android app using the following wrapper code:

Once this starts and I hit the back key and the onPause() executes how best to cancel the
async execution?

Async.executeAsync(aDevice, new Async.ApiWork<ParticleDevice, Integer>() {

    public Integer callApi(ParticleDevice particleDevice)
            throws ParticleCloudException, IOException {
        return particleDevice.getVariable("myVariable");
    }

    @Override
    public void onSuccess(Integer value) {
        Toaster.s(MyActivity.this, "Room temp is " + value + " degrees.");
    }

    @Override
    public void onFailure(ParticleCloudException e) {
        Log.e("some tag", "Something went wrong making an SDK call: ", e);
        Toaster.l(MyActivity.this, "Uh oh, something went wrong.");
    }
});

the executeAsync() call should give you a handle to the process by which you can control the process.

var execHandle = Async.executeAsync(aDevice, new Async.ApiWork<ParticleDevice, Integer>() { ... }
...
execHandle.Abort();
1 Like