Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unchecked Call to 'execute(Params...)' as a member of raw type 'android.os.AsyncTask'

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...

like image 314
doovers Avatar asked May 02 '15 03:05

doovers


2 Answers

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.

  1. Params, the type of the parameters sent to the task upon execution.

  2. Progress, the type of the progress units published during the background computation.

  3. Result, the type of the result of the background computation.

like image 191
Surely Avatar answered Oct 16 '22 06:10

Surely


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 。

like image 3
burulangtu Avatar answered Oct 16 '22 06:10

burulangtu