There are three different implementations of an AsyncTask
:
public class DownloadTask extends AsyncTask<String, Integer, Boolean>
public class JsonParserTask extends AsyncTask<Object, Void, Boolean>
public class PostCommentTask extends AsyncTask<String, Void, HttpRequestResult>
I would like them to extend a BaseAsyncTask
which I can use for dependency injection then. The class signatur of AsyncTask
looks like this:
public abstract class AsyncTask<Params, Progress, Result>
How can I extend AsyncTask
while maintaining the different parameters?
| DownloadTask
AsyncTask <-- BaseAsyncTask <--| JsonParserTask
| PostCommentTask
Why Android AsyncTask is Deprecated? Here is the official reason it is deprecated. AsyncTask was intended to enable proper and easy use of the UI thread. However, the most common use case was for integrating into UI, and that would cause Context leaks, missed callbacks, or crashes on configuration changes.
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
You can either cancel the AsyncTask in the onStop method of your activity or you can let your async task finish, and not loose its progress and relink it to the next instance of your activity.
Try:
abstract class BaseAsyncTask<Params, Progress, Result>
extends AsyncTask<Params, Progress, Result>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With