我有一个活动,我在其中调用一项服务,该服务可能需要一段时间才能完成,直到该服务未完成,单击的菜单选项应返回错误消息,例如“数据尚未准备好,请稍后再试” ,我想在抛出该错误之前给它几秒钟的时间来完成,在此期间,我想在屏幕上显示一个进度对话框。这是我的代码:
if(calculatedValue.equals(NOT_YET_CALCULATED)){
//show progress dialog
ProgressDialog progress = ProgressDialog.show(this, "", getResources().getString(R.string.wait), true);
long timeStarted = System.currentTimeMillis();
while(calculatedValue.equals(NOT_YET_CALCULATED) && System.currentTimeMillis() - timeStarted < 1500){
// wait for at most 1.5 seconds
}
progress.dismiss();
if(calculatedValue.equals(NOT_YET_CALCULATED)){
//if it's still not there, there's probably a problem, show generic alert dialog
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setTitle(R.string.not_yet_calulated_alert_title);
dialog.setMessage(getResources().getString(R.string.not_yet_calulated_alert_message));
dialog.show();
}else{
startActivity(j);
}
}else{
startActivity(j);
}
让我解释一下:我检查该值是否存在,如果不存在,我会显示一个进度图标(我要画圆圈)1.5 秒。如果在那之后它仍然不存在,我放弃并显示错误消息。
问题是进度的东西没有显示在屏幕上。我究竟做错了什么?
谢谢,即