class StudentTask extends android.os.AsyncTask<Void, String, String> {
Context mContext;
private ProgressDialog myDialog;
StudentTask(Context loginActivity){
this.mContext=loginActivity;
}
@Override
protected void onPreExecute() {
Log.e("async", "onPreExecute: try to fetch data " );
myDialog=new ProgressDialog(mContext);
myDialog.setTitle("Loading!");
myDialog.setIndeterminate(true);
myDialog.setMessage("Please Wait!");
myDialog.show();
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(s!=null){
myDialog.dismiss();
Log.e("async","result is shown" );
}
}
在MainActivity.java中
StudentTask studentTask = new StudentTask(LoginActivity.this);
json = studentTask.execute().get();