androidandroid-asynctaskandroid-async-http

Why AsyncTask can't implement methods except doInBackground?


In Android Studio, I've tried to implement the methods interface of AsyncTask, but it only shows method doInBackgound(). I've tried to place the cursor on the AsyncTask and then press Alt+Enter, but it only offers method doInBackgound().

screenshot

import android.os.AsyncTask;
import java.net.URL;
public class MyTask extends AsyncTask<URL, Integer, Long> {
    @Override
    protected Long doInBackground(URL... urls) {
        return null;
    }
}

Solution

  • The reason you're seeing only the AsyncTask::doInBackground(URL...) is because the method is not implemented in the abstract class AsyncTask.

    However, the others have default implementations and so you can only override them. If you need IntelliJ or Android Studio to suggest the others, you need to do CTRL + O. This will suggest other methods you can override from the parent classes.