In a scenario where I have a UI that will be updated from a separate thread (using AsyncTask), I can define the AsyncTask as an inner class of the activity, but this has two downsides I find problematic:
- It makes the source files very large, reducing efficiency in managing the code
- It makes it hard to reuse the thread class
What’s a good solution? Use an inner class, but abstract everything it does to other classes? Pass a reference to the Activity to the AsyncTask? Always define the AsyncTask class as an inner class and just accept source files will be large?
Quite a few examples I have seen just pass a
Contextinto the constructor of theAsyncTask.I would be interested to hear if anyone else uses any other approaches.