我正在尝试在解雇另一个对话框后直接显示对话框。
@Override
public void onLoginFailure(Exception e, boolean ttl) {
if(DialogUtils.isDialogShowing()){
//dismisses progress dialog
DialogUtils.DIALOG.dismiss();
}
DialogUtils.showExceptionDialog(this, "TTL Expired.");
}
DialogUtils.java:
public volatile static Dialog DIALOG;
public static boolean isDialogShowing() {
return (DIALOG!=null && DIALOG.isShowing());
}
public static Dialog showExceptionDialog(final Context ctx, final String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.exception_title);
builder.setMessage(message);
builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
if(isDialogShowing()) {
DIALOG.dismiss();
}
DIALOG = builder.create();
DIALOG.show();
return DIALOG;
}
public static Dialog showLoggingInProgressDialog(final Context ctx, final boolean cancellable) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setCancelable(cancellable);
builder.setTitle(R.string.dialog_login_title);
//ProgressBar pb = new ProgressBar(ctx);
//pb.setIndeterminate(true);
//builder.setView(pb);
if(isDialogShowing()) {
DIALOG.dismiss();
}
DIALOG = builder.create();
DIALOG.show();
return DIALOG;
}
在此代码中,当调用onLoginFailure时,将显示“正在登录...”进度对话框。我尝试关闭该对话框以显示错误对话框,但在新对话框上调用.show()会冻结该应用程序。我做错了什么?
更新(2013年12月16日8:53): 更改要执行失败的操作不会冻结应用程序,但Toast文本永远不会显示...?
@Override
public void onLoginFailure(Exception e, boolean ttl) {
if(DialogUtils.isDialogShowing()){
DialogUtils.DIALOG.dismiss();
}
if(ttl)
//DialogUtils.showExceptionDialog(this, "TTL Expired.");
Toast.makeText(this, "Login failed:\nTTL Expired...", Toast.LENGTH_SHORT);
else if(e!=null)
//DialogUtils.showExceptionDialog(this, e);
Toast.makeText(this, "Login failed:\n" + e.getMessage(), Toast.LENGTH_SHORT);
}
答案 0 :(得分:0)
while(isDialogShowing()) {
//
}
您正在运行无限循环?
答案 1 :(得分:0)
替换
while(isDialogShowing()) {
//
}
DIALOG = builder.show();
带
if(isDialogShowing) {
DIALOG.dismiss();
}
DIALOG = builder.create();
DIALOG.show();
在show .... Dialog(....)方法......