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

misuse of AsyncTask #566

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

misuse of AsyncTask #566

pangeneral opened this issue Aug 13, 2019 · 1 comment

Comments

@pangeneral
Copy link

According to our research, there are misuses about the following AsyncTask class:
de.geeksfactory.opacclient.frontend.LibraryListActivity.LoadLibrariesTask

The problems are:

  1. LoadLibrariesTask is an inner class of LibraryListActivity, which means it holds strong reference the Activity, which can lead to memory leak when the Activity is destroyed and the AsyncTask did not finish;
  2. The instance of LoadLibrariesTask are not cancelled before the Activity is destroyed, which can lead to the wrong invocation of onPostExecute() if the Activity is destroyed
  3. The doInBackground() did not check the status of AsyncTask.

I think we can make following changes to fix the misuse problems:

  1. LoadLibrariesTask should be a static inner class.
  2. loadLibrariesTask, the instance of LibraryListActivity should invoke cancel() in the onDestroy() method of LibraryListActivity if it is not null
  3. In the loop of doInBackground() method, check whether AsyncTask is cancelled via isCancelled(). If current AsyncTask is cancelled, jump out of the loop.

These are my suggestions above, thank you.

@raphaelm
Copy link
Member

Feel free to submit a pull request for this, thanks!

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