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

AsyncTask is not cancelled #26

Open
pangeneral opened this issue Aug 13, 2019 · 1 comment
Open

AsyncTask is not cancelled #26

pangeneral opened this issue Aug 13, 2019 · 1 comment

Comments

@pangeneral
Copy link

There is a annoymous AsyncTask object in au.com.wallaceit.reddinator.core.SubredditManager.loadDefaultSubredditsau methods. This object won't be cancelled. I think we should replace it with non-anonymous object and cancel it in the onDestroy() method.

public void loadDefaultSubreddits(){
	try {
		subreddits = new JSONObject(defaultSubreddits); // start with front page and all
	} catch (JSONException e) {
		e.printStackTrace();
	}
	new LoadDefaultSubredditsTask().execute();
}

Similarly, the finish() method in au.com.wallaceit.reddinator.activity can't guarantee loadPostTask will be cancelled.

@micwallace
Copy link
Owner

There is no need to destroy an async task. As outlined here it will lose it's reference to context and be disposed through garbage collection:
https://stackoverflow.com/questions/29867948/android-external-async-task-with-callback-do-i-need-to-dispose-the-callback

The reason that I am not cancelling them is because in most cases such as voting or commenting, even if the user exits the activity, it's still good to continue the operation in the background. However if you feel like there are some that should be cancelled then feel free to open a pull request.

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

2 participants