micwallace/reddinator

AsyncTask is not cancelled

Opened this issue · 1 comments

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.

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.