当我执行http-request并移动到其他活动或片段时,我会调用一个大的进程,
问题是,该过程没有完成,然后显示为空白,然后转移到另一个活动。
问题是,我们如何设置计时器和超时以及我可以放置行代码的位置。
这是我目前的代码
public class BigProccess extends AsyncTask<Void, Integer, Void> {
private Context mContext;
ProgressDialog mProgress;
private int mProgressDialog=0;
public BigProccess(Context context, int progressDialog){
this.mContext = context;
this.mProgressDialog = progressDialog;
}
@Override
public void onPreExecute() {
mProgress = new ProgressDialog(mContext);
mProgress.setMessage("Loading...");
// if (mProgressDialog== ProgressDialog.STYLE_HORIZONTAL){
mProgress.setIndeterminate(false);
mProgress.setMax(100);
mProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgress.setCancelable(false);
// }
mProgress.show();
}
@Override
protected void onProgressUpdate(Integer... values) {
// if (mProgressDialog== ProgressDialog.STYLE_HORIZONTAL){
mProgress.setProgress(values[0]);
// }
}
@Override
protected Void doInBackground(Void... values) {
try {
//This is to simulate there is a heavy process is running
//and we make it slow down by 500 ms for each number
for (int i =1; i<=10;i++){
publishProgress(i*10);
Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mProgress.dismiss();
// Toast.makeText(mContext,"Done!!!",Toast.LENGTH_LONG).show();
}
}
我尝试修改了线程。睡眠时间为15000毫秒,但它无法正常工作。
任何帮助都将不胜感激。