概述
小编典典
像下面这样
class GetStuffAsyncly extends AsyncTask {
String dialogString;
ProgressDialog dialog;
Context context;
AsyncListener listener;
// my vars....
public GetStuffAsyncly(String dialogMessage, Context con, AsyncListener listener) {
this.dialog = new ProgressDialog(con);
this.dialogString = dialogMessage;
this.context = con;
this.listener = listener;
}
/**
* Before starting background thread Show Progress Dialog
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
listener.onTaskStarted();
}
@Override
protected String doInBackground(String... args) {
// do stuff in background...
return data;
}
/**
* After completing background task Dismiss the progress dialog
**/
protected void onPostExecute(String jsonString) {
// dismiss the dialog after getting all data
dialog.dismiss();
listener.onTaskFinished(jsonString);
}
}
和听众课
public interface AsyncListener {
void onTaskStarted();
void onTaskFinished(String data);
}
你可以这样打电话
new GetStuffAsyncly(message, this, new AsyncListener() {
@Override
public void onTaskStarted() {
//do your stuff
}
@Override
public void onTaskFinished(String data) {
//Do your stuff;
}
}).execute(parameter);
2020-11-01
最后
以上就是危机月饼为你收集整理的java中异步返回结果_如何从异步调用返回结果的全部内容,希望文章能够帮你解决java中异步返回结果_如何从异步调用返回结果所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复