Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel() does not cancel #4

Open
Martin-Hogge opened this issue Dec 13, 2016 · 0 comments
Open

Cancel() does not cancel #4

Martin-Hogge opened this issue Dec 13, 2016 · 0 comments

Comments

@Martin-Hogge
Copy link

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant