vxh.viet
6/28/2016 - 6:36 AM

How to prevent AsyncTask from leaking Context?

How to prevent AsyncTask from leaking Context?

Source: StackOverflow, Blog, Medium, Garena

Answer: if the AsyncTask is an inner class, then define it as static and if it need a Context to do stuff then use WeakReference. If the task takes a lot of time then just ditch AsyncTask and use RxJava (see RxJava Gist for detail).