0

The dialog:

public class ClearDialog extends Dialog {

    private MainActivity context;

    public ClearDialog(MainActivity context) {
        super(context);
        this.context = context;
        setContentView(R.layout.clear_dialog);
        setTitle("something");
        setCanceledOnTouchOutside(false);
        setCancelable(true);
    }
    /* not overriding anymore
    @Override
    public void onBackPressed() {
        return;
    }
    still doesnt work */

    @Override
    protected void onStart() {
        super.onStart();
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = preferences.edit();
        editor.clear();
        editor.commit();
        ResourceHelpers.removeAllResources();
        context.onResourcesDeleted();
    }

}

The Activity:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.itemLogoff:
            loginDialog.show(); //this is another dialog
            break;
        case R.id.itemSync:
            Intent syncer = new Intent(MainActivity.this, SyncActivity.class);
            MainActivity.this.startActivity(syncer);
            break;
        case R.id.itemClear:
            new AlertDialog.Builder(this)
            .setIcon(R.drawable.ic_action_alert)
            .setTitle("something")
            .setMessage("something")
            .setPositiveButton("something", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    showDeleteDialog();
                }
            })
            .setNegativeButton("something", null)
            .show();
            break;
        }
        return true;
    }

    private void showDeleteDialog() {
        cd = new ClearDialog(this); //this is the dialog
        cd.show();
    }

    public void onResourcesDeleted() {

        cd.dismiss();
        loginDialog.show();
    }

So.. The user clicks on "Delete all data" from the ActionBar (optionsmenu). I open an AlertDialog asking if he's sure. Then if he's sure, I open a dialog that shows a spinning ProgressBar.

The problem: it won't dismiss!

The loginDialog (all data is lost so I want the user to login again...) comes up in the background. The ClearDialog won't dismiss...

4

3 回答 3

1

I think that the problem is here (don't override in this way that method):

@Override
    public void onBackPressed() {
        return;
    }

You can already obtain a modal dialog with .setCancelable(false)

Please take a loog at this documentation: http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog

于 2012-08-14T13:08:12.053 回答
0

为对话提供以下属性 .setCancelable(true);

就像代码中的 .setTitle() 或 .setMessage 一样......

于 2012-08-14T13:17:03.103 回答
0

除了您应该遵循的 StErMi 的答案之外,还要在 onResourcesDeleted() 方法中切换两行。登录对话框被调用,并在你的解雇被调用之前接管。

public void onResourcesDeleted() {
    cd.dismiss();
    loginDialog.show();
}
于 2012-08-14T13:24:09.753 回答