Can you fire an event when Android Dialog is dismi

2019-01-26 03:07发布

Say I have a created a dialog in my Android app like so:

private static ProgressDialog dialog;
dialog = ProgressDialog.show(MainActivity.this, "", "Downloading Files. Please wait...", true);

Now, is it possible to fire an event when the following is called?

dialog.dismiss();

The reason I want to do this and not just call my method after dialog.dismiss(); is because the Dialog dismiss is called within a static class and the next thing I want to do is load a new Activity (which cannot be done using Intents within a static class).

4条回答
Ridiculous、
2楼-- · 2019-01-26 03:25

Whenever a dialog is closed either by clicking PositiveButton, NegativeButton, NeturalButton or by clicking outside of the dialog, "onDismiss" is always gets called automatically so do your stuff inside the onDismiss() method e.g.,

@Override
public void onDismiss(DialogInterface dialogInterface) {
    ...
}

You don't even need to call dismiss() method.

查看更多
3楼-- · 2019-01-26 03:28

Use setOnDismissListener method for the dialog.

dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        if (mIsSettingsDirty)
            refreshRecyclerView();
    }
});
查看更多
祖国的老花朵
4楼-- · 2019-01-26 03:45

Use an OnDismissListener.

There is a setOnDismissListener(...) method in the class Dialog

查看更多
小情绪 Triste *
5楼-- · 2019-01-26 03:48

Sure you can - check:

  public void onDismiss(DialogInterface dialogInterface)
  {
        //Fire event
  }
查看更多
登录 后发表回答