package com.example.uiactivity;
import android.os.AsyncTask;
import android.widget.Toast;
public class DownloadTask extends AsyncTask<Void,Integer,Boolean> {
@Override
protected void onPreExecute() {
progressDialog.show();
}
@Override
protected Boolean doInBackground(Void... voids) {
int i=0;
while (true){
i++;
publishProgress(i);
if(i>=100){
break;
}
}
return true ;
}
@Override
protected void onProgressUpdate(Integer... values) {
progressDialog.setMessage("Download"+String.valueOf(values[0])+"%")
}
@Override
protected void onPostExecute(Boolean aBoolean) {
if(aBoolean){
Toast.makeText(context,"Download success!",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context,"Download failed!",Toast.LENGTH_SHORT).show();
}
}
}