I have seen different coding styles when it comes to implementing AsyncTask
on Android for lightweight background operations. Though I have used static nested class implementation by far, I wanted to understand when and why are these implementations for AsyncTask
preferred?
- Static nested class
- Non-static inner class
- Separate public class.
I believe the inner classes helps to tightly bound the class to a particular activity/fragment (encapsulation) and also code organization. So, what decides static vs non-static?
With separate classes, though it might be reusable, there's a lot of boiler plate code with use of interfaces to communicate and update the UI elements of fragment/activities. Also, how are each implementations susceptible to memory leaks - for instance when the screen rotates?
Possible duplicate : What's the correct way to implement AsyncTask? static or non static nested class?