package com.example.viewpager_homework_async;
import com.example.viewpager_homework_tools.HttpUtils;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;
public class GetDataAsyncTask extends AsyncTask<String, Void, String>{
private Context context;
private ProgressDialog dialog;
private GetDataCallback callback;
public GetDataAsyncTask(Context context,GetDataCallback callback) {
super();
this.context = context;
this.callback = callback;
dialog = new ProgressDialog(context);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.setTitle("提示信息");
dialog.setMessage("正在拼命加载中....");
dialog.show();
}
@Override
protected String doInBackground(String... params) {
String json= HttpUtils.getJsonContent(params[0]);
return json;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
dialog.dismiss();
if (!TextUtils.isEmpty(result)) {
callback.sendData(result);
}
}
public interface GetDataCallback{
public void sendData(String json);
}
}
Android 使用 AsyncTask异步加载 和 接口回调 获取联网获取到的 json数据 工具类
最新推荐文章于 2021-05-27 08:40:23 发布