AsyncJobLibrary
AsyncJobLibrary copied to clipboard
Cancel() does not cancel
Hi !
First, thanks for this great library !
But I got an issue (or maybe a misunderstanding from myself) : I want to cancel a started AsyncJob in case we dismiss manually a loading dialog but when I call AsyncJob.cancel() it seems to have no effects. The callback onResult is still call with the result of doAsync() like nothing has happened.
What I was assuming is that the cancel() method would
- Avoid
onResultto be call. - Or call it with a flag like "CANCELLED"
But I don't have any way of telling if my AsyncJob has been cancelled.
Here is my code :
final AsyncJob<StatisticsTable> asyncJob = new AsyncJob<>();
asyncJob.setActionInBackground(new AsyncJob.AsyncAction<StatisticsTable>() {
@Override
public StatisticsTable doAsync() {
return DashboardHelper.getInstance().getDashboard(
StatisticsActivity.this,
period,
DashboardHelper.DASHBOARD_TYPE.values()[position]
);
}
});
asyncJob.setActionOnResult(new AsyncJob.AsyncResultAction<StatisticsTable>() {
@Override
public void onResult(StatisticsTable table) {
dismissLoadingDialog();
switchFragment(NAVIGATION_INDEX_DASHBOARD_ITEM, table);
}
});
//Add a cancel listener on the loading dialog to cancel the async task once the user
//has manually dismiss the dialog.
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
asyncJob.cancel();
}
});
asyncJob.start();
Thank's for help !