You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
They hold strong reference to the GUI element of Activity, which can lead to memory leak when the Activity is destroyed and the AsyncTask did not finish
Their instances are not cancelled before the Activity is destroyed, which can lead to the wrong invocation of onPostExecute
I think we can make following changes to fix the misuse problems:
I think the GUI-related fields should be wrapped into WeakReference. Take private final RestoreMessagesActivity _context as example, it can be changed tp private final WeakReference<RestoreMessagesActivity> _context.
Add a AsyncTask field in the corresponding Activities which use AsyncTask. These field refer to the annoymous AsyncTask object such as new ASyncSMSRecovery.SMSRecoveryTask(me, _account).execute(). Then invoke cancel() in the onDestroy() method of Activities.
These are my suggestions above, thank you.
The text was updated successfully, but these errors were encountered:
According to our research, there are misuses about the following two AsyncTask classes:
The problems are:
I think we can make following changes to fix the misuse problems:
private final RestoreMessagesActivity _context
as example, it can be changed tpprivate final WeakReference<RestoreMessagesActivity> _context
.new ASyncSMSRecovery.SMSRecoveryTask(me, _account).execute()
. Then invokecancel()
in the onDestroy() method of Activities.These are my suggestions above, thank you.
The text was updated successfully, but these errors were encountered: