I'm following the google android tutorial on Udacity but in the specified code, I'm getting the following warning:
Unchecked Call to 'execute(Params...)' as a member of raw type 'android.os.AsyncTask'
on this code:
DoSomethingTask myTask = new DoSomethingTask();
myTask.execute(); // Warning here
DoSomethingTask:
public class DoSomethingTask extends AsyncTask {
protected Object doInBackground(Object[] params) {
...
}
}
Can anyone explain this warning and how to fix it? It seems it should work according to the instructions...
The warning is caused by the params for the task. Try to use:
extends AsyncTask<Void, Void, Void>{
protected Object doInBackground() {
}
}
or use:
extends AsyncTask<Object, Void, Void>{
protected Object doInBackground(Object[] params) {
}
}
myTask.execute(anyObject);
Explanation:
This document explains the meaning of the three types for AsyncTask.
Params, the type of the parameters sent to the task upon execution.
Progress, the type of the progress units published during the background computation.
Result, the type of the result of the background computation.
change
AsyncTask asyncTask = new AsyncTask<Object, Void, String>() {
@Override
protected String doInBackground(Object... params) {
return "";
}
};
asyncTask.execute();
to
AsyncTask<Object, Void, String> asyncTask = new AsyncTask<Object, Void, String>() {
@Override
protected String doInBackground(Object... params) {
return "";
}
};
asyncTask.execute();
AsyncTask reference need the same as AsyncTask Class ,and IDE will not warning 。
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