title: Fragment Back stack from second fragment to first fragment
body: <p>I have viewpager tab fragment and from one tabb fragment on button click it open another fragment and another second fragment i want to add event of backpress as i am doing backpress it exiting application as i have written code of Double back press exit code in my root fragment and i dont want this code to call in my another second fragment as i want simply one step back to my previous fragment
  As here is the code</p>
  
  <pre><code> R.id.Recharge -&gt; {
  
              val pl = Payment_History()
  
              fragmentTransaction = fragmentManager!!.beginTransaction()
              fragmentTransaction.replace(R.id.frame_container, paypal)
              fragmentTransaction.addToBackStack(null)
              fragmentTransaction.commit()
  
  
          }
  </code></pre>
  
  <p>In Payment history i am calling on Back press override function</p>
  
  <pre><code>override fun onBackPressed(): Boolean {
      super.onBackPressed()
  }
  </code></pre>
  
  <p>and on clicking on Paymenthistory it called exit code from application. i want that it back to previous fragment. As I have written this fragment code but not working.
  Any one have idea how to back second nested fragment to previous fragment.</p>
  
  <p>My OnBackPress code in my MainActivity</p>
  
  <pre><code>    override fun onBackPressed() {
      // TODO Auto-generated method stub
      try {
      if (getFragmentManager().getBackStackEntryCount() == 0) {
  
          if (doubleBackToExitPressedOnce) {
  
              //super.onBackPressed();
              val startMain = Intent(Intent.ACTION_MAIN)
              startMain.addCategory(Intent.CATEGORY_HOME)
              startMain.flags = Intent.FLAG_ACTIVITY_NEW_TASK
              pref!!.setLoggedIn(true)
              startMain.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
              startMain.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
              startActivity(startMain)
              return
          }
  
          this.doubleBackToExitPressedOnce = true
          Toast.makeText(this, "Please click again to exit", Toast.LENGTH_SHORT).show()
  
          Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
      }
  
          }catch (e:Exception){
          println("homemessage"+ e.message)
      }
  }
  </code></pre>