title: App exits on presing back button inside fragments within navigation drawer
body: <p>My app exits when i try to move from child fragment to parent fragment(it doesn't crashes).Here LandingActivity.java is main activity in which I am calling fragment ChannelGrid.java which calls fragment GridMain.java.When i presses back button of mobile in fragment GridMain app exits rather than moving to ChannelGrid.java.I have added addToBackStack("tag") to fragments and also tried using onKey()..I tested my app on different devices also..I checked out other solutions with same issue and tried them but nothing works..</p>
  
  <p>Navigation Drawer-LandingActivity.java-ChaanelGrid.java(Fragment)-GridMain.java(Fragment)</p>
  
  <p>LandingActivity.java</p>
  
  <pre><code>   currentFragment = new ChaanelGrid();
  
                  currentFragment.setArguments(args);
                  frgManager = getFragmentManager();
  
                  frgManager.beginTransaction().add(R.id.content_frame, currentFragment).addToBackStack("tag")
                          .commit();
  </code></pre>
  
  <p>ChaanelGrid.java</p>
  
  <pre><code>Fragment currentFragment = new GridMain();
  
  
  
                      FragmentManager frgManager;
                      frgManager = getFragmentManager();
                      frgManager.beginTransaction().add(R.id.content_frame, currentFragment).addToBackStack("GridMain")
                              .commit()
  </code></pre>
  
  <p>GridMain.java(i tried without onKey() method also but didn't worked)</p>
  
  <pre><code>rootView.setOnKeyListener(new View.OnKeyListener() {
  
  
     @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
              if (keyCode == KeyEvent.KEYCODE_BACK)
              {
                  Fragment currentFragment = new ChaanelGrid();
  
  
                  FragmentManager frgManager;
                  frgManager = getFragmentManager();
                  frgManager.beginTransaction().replace(R.id.content_frame, currentFragment)
                          .commit();
                  return true;
              }
  </code></pre>
  
  <p>logcat verbose</p>
  
  <pre><code>   10-31 21:46:57.954  24452-24452/D/ActivityThread﹕ ACT-AM_ON_PAUSE_CALLED ActivityRecord{41eb8b98 token=android.os.BinderProxy@41bb9828 {xyz/xyz..activity.LandingActivity_}}
  10-31 21:46:57.971  24452-24452/ D/ActivityThread﹕ ACT-PAUSE_ACTIVITY_FINISHING handled : 0 / android.os.BinderProxy@41bb9828
  10-31 21:46:58.007  24452-24452/ V/InputMethodManager﹕ focusOut: android.widget.GridView@41f06f40 mServedView=android.widget.GridView@41f06f40 winFocus=false
  10-31 21:46:58.297  24452-24452/ I/SurfaceTextureClient﹕ [0x5143bc58] frames:44, duration:1.002000, fps:43.883736
  10-31 21:46:58.350  24452-24452/ D/OpenGLRenderer﹕ Flushing caches (mode 0)
  10-31 21:46:58.432  24452-24452/ D/OpenGLRenderer﹕ Flushing caches (mode 0)
  10-31 21:46:58.753  24452-24452/ D/OpenGLRenderer﹕ Flushing caches (mode 0)
  10-31 21:46:58.754  24452-24452/ D/OpenGLRenderer﹕ Flushing caches (mode 0)
  10-31 21:46:58.755  24452-24452/ D/OpenGLRenderer﹕ Flushing caches (mode 2)
  10-31 21:46:58.879  24452-24452/ D/ActivityThread﹕ ACT-DESTROY_ACTIVITY handled : 1 / android.os.BinderProxy@41bb9828
  </code></pre>
  
  <p>I tried adding following in LandingActivity.java</p>
  
  <pre><code>@Override
  
  public void onBackPressed() {
      FragmentManager frgManager;
      frgManager = getFragmentManager();
  
      Fragment fragment = fragmentManager.findFragmentByTag("GridMain");
      if (fragment != null) {
          GridMain gridMain = (GridMain) fragment;
          if (!gridMain.onBackPressed()) {
              super.onBackPressed();
          }
      }
      else {
          super.onBackPressed();
      }
  }
  </code></pre>
  
  <p>and following in GridMain.java</p>
  
  <pre><code>   protected boolean onBackPressed() {
          FragmentManager frgManager;
          frgManager = getFragmentManager();
          frgManager.popBackStack();
          return true;
      }
  </code></pre>
  
  <p>Using Log i checked tht onBackPressed() of LandingActivity.java is being called but still the same output..</p>