Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

java - Can't Override onPostExecute() method in AsyncTask Class or get it to trigger

I am having trouble getting the onPostExecute() method to call when running an AsyncTask. When I try to set up my class extending AsyncTask in which the onPostExecute() is overridden I get the following build error.

'The method onPostExecute() of type AsyncTaskExampleActivity must override or implement a supertype method'

I have tried getting rid of the @Override annotation. This gets rid of the build error but the method still does not execute. If any one would be so kind as to point out what I'm overlooking I would greatly appreciated it.

Code:

package com.asynctaskexample;

import android.os.AsyncTask;

public class AsyncTaskExampleActivity extends AsyncTask<Void, Void, Void> {

AsyncTaskExampleActivity(){
super();
    }

@Override
protected void onPreExecute() {
    }

@Override
protected Void doInBackground(Void... params) {
    return null;
}

@Override
protected void onPostExecute() {
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OnPostExecute() takes an argument (the object you return from doInBackground()). Change it to protected void onPostExecute(Void v). If you don't provide the argument, the method signatures do not match and the override annotation starts to complain that there is no function to override with this signature.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...