opacclient
opacclient copied to clipboard
misuse of AsyncTask
According to our research, there are misuses about the following AsyncTask class:
de.geeksfactory.opacclient.frontend.LibraryListActivity.LoadLibrariesTask
The problems are:
LoadLibrariesTaskis an inner class ofLibraryListActivity, 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;- The instance of
LoadLibrariesTaskare not cancelled before the Activity is destroyed, which can lead to the wrong invocation ofonPostExecute()if the Activity is destroyed - The
doInBackground()did not check the status of AsyncTask.
I think we can make following changes to fix the misuse problems:
LoadLibrariesTaskshould be a static inner class.loadLibrariesTask, the instance ofLibraryListActivityshould invokecancel()in theonDestroy()method ofLibraryListActivityif it is not null- In the loop of
doInBackground()method, check whether AsyncTask is cancelled viaisCancelled(). If current AsyncTask is cancelled, jump out of the loop.
These are my suggestions above, thank you.
Feel free to submit a pull request for this, thanks!