Skip to content

Cancel() does not cancel #4

Description

@Martin-Hogge

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 onResult to 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 !

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions