Java 在加载新活动之前显示进度对话框
当用户单击按钮启动新活动时,我试图显示一个进度对话框。微调器应显示在当前页面上,直到出现其他活动。(活动有时可能需要4-5秒才能启动,如果没有微调器,它只会显示一个按下的按钮,看起来冻结了) 这就是我所拥有的,只有当我删除Java 在加载新活动之前显示进度对话框,java,android,progressdialog,Java,Android,Progressdialog,当用户单击按钮启动新活动时,我试图显示一个进度对话框。微调器应显示在当前页面上,直到出现其他活动。(活动有时可能需要4-5秒才能启动,如果没有微调器,它只会显示一个按下的按钮,看起来冻结了) 这就是我所拥有的,只有当我删除hideProgressDialog()时它才起作用,但很明显,当我返回到上一个活动时,微调器仍然存在 我做错了什么 进度对话框: public void showProgressDialog(Context context) { if(this.progres
hideProgressDialog()时它才起作用代码>,但很明显,当我返回到上一个活动时,微调器仍然存在
我做错了什么
进度对话框:
public void showProgressDialog(Context context) {
if(this.progressDialog != null) {
this.progressDialog.dismiss();
this.progressDialog = null;
}
this.progressDialog = ProgressDialog.show(context, "", "Chargement en cours, veuillez patienter");
}
public void hideProgressDialog() {
if(this.progressDialog != null) {
this.progressDialog.dismiss();
this.progressDialog = null;
}
}
public void startActivity(Context context, Class<? extends Activity> activityClass) {
try {
showProgressDialog(context);
Intent intent = new Intent(this, activityClass);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
hideProgressDialog();
}
catch(Throwable e) {
e.printStackTrace();
}
}
@Override
public void onClick(View view) {
if(view.getId() == R.id.changeBannerButton) {
getBaseApplication().startActivity(this, BannerListActivity.class);
}...
功能:
public void showProgressDialog(Context context) {
if(this.progressDialog != null) {
this.progressDialog.dismiss();
this.progressDialog = null;
}
this.progressDialog = ProgressDialog.show(context, "", "Chargement en cours, veuillez patienter");
}
public void hideProgressDialog() {
if(this.progressDialog != null) {
this.progressDialog.dismiss();
this.progressDialog = null;
}
}
public void startActivity(Context context, Class<? extends Activity> activityClass) {
try {
showProgressDialog(context);
Intent intent = new Intent(this, activityClass);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
hideProgressDialog();
}
catch(Throwable e) {
e.printStackTrace();
}
}
@Override
public void onClick(View view) {
if(view.getId() == R.id.changeBannerButton) {
getBaseApplication().startActivity(this, BannerListActivity.class);
}...
在onResume()
方法中调用hideProgressDialog()
。这样,如果用户按下后退按钮,将调用onResume()
方法并立即隐藏进度对话框。首先,您应该将新的DialogFragment类与FragmentManager一起使用。因为showdialog()已从API级别8弃用
接下来,您应该使用showdialog和removedialog添加和删除对话框
您应该使用onCreateDialog来处理对话框和操作。就像启动一个新线程来运行一样,在显示progressdialog时执行任务 在活动开始时,尝试在单独的线程中加载数据。但在该过程开始之前,请显示“进度”对话框。现在,流程完成后,使用runOnUI隐藏进度对话框
这是:
所以。。。为什么活动需要这么长时间才能启动?