title: Listen to Bottom sheet dialog fragment dismissal and open a new fragment
body: <p>I have a bottomsheetdialog fragment with 2 buttons on it. I'm opening it on <code>fragment1</code>.  On <code>button1</code> click, it should dismiss the dialog whereas on clicking <code>button2</code> it should first dismiss the dialog and then open a new fragment <code>Fragment2</code>. Right now I'm able to dismiss and move to <code>fragment2</code> but only problem is both the actions are happening at the same time. I want the dialog to dismiss first and then start the second fragment. </p>
  
  <p><a href="https://i.stack.imgur.com/tAn4M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tAn4M.png" alt="enter image description here"></a></p>
  
  <p>MY CODE:</p>
  
  <p><strong>Fragment 1:</strong></p>
  
  <pre><code> private var button2ClickListner = object : AcknowledgmentDialogFragment.AcknowledgmentCTAAction {
          override fun onContinueClick() {
             initializeFragment2()
          }
  
      }
      private fun showAcknowledgment() {
          AcknowledgmentDialogFragment = AcknowledgmentDialogFragment().newInstance(button2ClickListner)
          AcknowledgmentDialogFragment.show(fragmentManager, AcknowledgmentDialogFragment.tag)
      }
  </code></pre>
  
  <p><strong>AcknowledgmentDialogFragment</strong></p>
  
  <pre><code>class AcknowledgmentDialogFragment : BottomSheetDialogFragment() {
  
  private lateinit var binding: BottomsheetLayoutAcknowledgmentBinding
  
  interface AcknowledgmentCTAAction {
      fun onContinueClick()
  }
  
  private lateinit var btn2: AcknowledgmentCTAAction
  
  fun newInstance(btnContinue: AcknowledgmentCTAAction): AcknowledgmentDialogFragment {
      this.btn2 = btn2
      return this
  }
  
  private fun subscribeForUiEvents() {
      binding.button1.setOnClickListener({
          dismiss()
      })
  
      binding.button2.setOnClickListener({
          dismiss()
          btn2.onContinueClick()
      })
  }
  
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      binding = DataBindingUtil.inflate(inflater, R.layout.bottomsheet_layout_acknowledgment, container, false)
      subscribeForUiEvents()
  
      return binding.root
  }
  
  override fun onActivityCreated(arg0: Bundle?) {
      super.onActivityCreated(arg0)
  
      dialog.window.decorView.findViewById&lt;View&gt;(android.support.design.R.id.touch_outside).setOnClickListener(null)
      dialog.window.attributes.windowAnimations = R.style.DialogAnimation
  }
  }
  </code></pre>