AsyncTask的封装

package com.gy.week3_dome1.util;

import android.content.Context;
import android.os.AsyncTask;

public class MyTask extends AsyncTask {
Context context;
String param;
String url;
private TaskListeners taskListener;
public MyTask(Context context,String param,String url) {
this.context = context;
this.param=param;
this.url=url;
}
//获取接口
public MyTask setTaskListener(TaskListeners taskListener ){
this.taskListener = taskListener ;
return this ;
}
@Override
protected String doInBackground(T… ts) {
return new HttpUrlUtils().getHttp(context,param,url);
}

@Override
protected void onPostExecute(String s) {
    super.onPostExecute(s);
    if (s!=null){
        taskListener.result(s);
    }
}
//定义接口
public interface TaskListeners{
    void result( String t );
}

}

你可能感兴趣的:(分享代码区)