How do I instantiate and call and class extending AsyncTask if I am passing nothing to it?
Also, I am setting a textview in the UI to the calculated result.
Thanks, Ben
Example implementation for Async without params and result Bitmap in onPostExecute result
/**
* My Async Implementation without doInBackground params
*
*/
private class MyAsyncTask extends AsyncTask<Void, Void, Bitmap> {
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap bitmap;
....
return bitmap;
}
protected void onPostExecute(Bitmap bitmap) {
....
}
}
In your activity, you should to add this implementation:
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
I think what you meant to ask was how do I write an AsyncTask that doesn't ask for any parameters. The trick is to define what you expect to use as parameter and return value in the extension of your class:
class MyClass extends AsyncTask<Void, Void, Void>
for example doesn't expect any parameters and doesn't return any either.
AsyncTask<String, Void, Drawable>
expects a String (or multiple strings) and returns a Drawable (from its own doInBackground
method to its own onPostExecute
method)
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