我在下面的代码中得到错误,说我必须实现至少一个继承的AsyncTask类方法,但我实现其中3个仍然会引发错误。有人在这段代码中看到任何问题
List<NameValuePair> login_details = new ArrayList<NameValuePair>();
new CheckUserValidation().execute(login_details);
class CheckUserValidation extends AsyncTask<List<NameValuePair>,Void,String>
{
@Override
protected void onPreExecute(){
super.onPreExecute();
pdialog = new ProgressDialog(RrdMainActivity.this);
pdialog.setMessage("Validating user...");
pdialog.setIndeterminate(false);
pdialog.setCancelable(false);
pdialog.show();
}
@Override
protected String doInBackground(List<NameValuePair>... params) {
List<NameValuePair> args;
args=params[0];
http_resp = httpparser.makeHttpRequest(url_validate_user, "GET", args);
try
{
int success_code = http_resp.getInt(TagSuccess);
if(success_code == 1)
{
return "valid";
}
else
{
return "invalid";
}
}catch(JSONException e){
e.printStackTrace();
}
return "valid";
}
@Override
protected void onPostExecute(String success_message){
if (success_message == "valid")
{
pdialog.dismiss();
Bundle b = new Bundle();
b.putString("imessage", http_resp.toString());
Intent i = new Intent(RrdMainActivity.this,AllClasses.class);
i.putExtras(b);
startActivity(i);
}
else
{
pdialog.setMessage("Invalid userid/password. please try again...");
pdialog.setCanceledOnTouchOutside(true);
}
}
}
提前感谢:)
答案 0 :(得分:2)
尝试添加 @覆盖 在你的doInBackground函数之前
答案 1 :(得分:1)
变化:
protected String doInBackground(List<NameValuePair> params) {
为:
protected String doInBackground(List<NameValuePair>... params) {
并添加:
@Override
答案 2 :(得分:0)
你应该覆盖你的doInBbackground方法,就像这样
@Override
protected String doInBackground(List<NameValuePair> params)
此外,我建议您使用此库进行背景工作,让您的生活更轻松 https://github.com/Arasthel/AsyncJobLibrary
这很简单..
AsyncJob.doInBackground(new AsyncJob.OnBackgroundJob() {
@Override
public void doOnBackground() {
startRecording();
}
});