title: In Kotlin ..How I can return from fragment to MainActivity
body: <p>in my program I have MainActivity and many fragments..
  I try the following code to return from fragment to MainActivity by 
  <code>onBackpressed()</code> method</p>
  
  <pre><code>override fun onBackPressed() {
  
      if(drawer_layout.isDrawerOpen(GravityCompat.START)) {
          drawer_layout.closeDrawer(GravityCompat.START)
      }
      else  if (fragment != null) {
      val intent = Intent(applicationContext, MainActivity::class.java)
      intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
      startActivity(intent)
  
       }
  
  
      else {
         super.onBackPressed()
      }
  }
  </code></pre>
  
  <p><strong>My first problem is:</strong></p>
  
  <p>it working good with Drawer and also open MainActivity
  but program not closed ..these main that</p>
  
  <pre><code>super.onBackPressed()
  </code></pre>
  
  <p>not working ..why </p>
  
  <p><strong>My second problem is:</strong></p>
  
  <p>after else If I need to use</p>
  
  <pre><code>getActivity().onBackpressed()
  </code></pre>
  
  <p>instead of the old one..</p>
  
  <p><em>Thanks All</em></p>