title: Recreate Fragments on BackKey Pressed
body: <p>Im trying to Solve a problem where when a user press back key, the fragment should be recreated rather than loading from back stack. I have a single Main activity with a frame layout and i replace the fragments within the single frame dynamically. the code below works when the user go from fragment within fragment. but when the user select from navigation drawer, the replaced fragment is going on to the top of backstack which is causing problems.</p>
  
  <p>Right now the code i wrote in BackKey Pressed Event </p>
  
  <pre><code>public override void OnBackPressed()
          {
  
              Android.Support.V4.App.FragmentManager.IBackStackEntry entry =
                  SupportFragmentManager.GetBackStackEntryAt(SupportFragmentManager.BackStackEntryCount - 1);
  
              string str = entry.Name;                   
  
              if (SupportFragmentManager.BackStackEntryCount == 0)
              {
                  this.Finish();
              }                
              else
              {
                  Fragment fr = (Fragment)MagicallyCreateInstance(str);
                  SupportFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, fr).Commit();   
                  SupportFragmentManager.PopBackStack();
  
              }                    
              base.OnBackPressed();
          }
  </code></pre>
  
  <p>i also have a replace fragment method which i use to replace fragments. but in this process the back key is getting disabled by default somehow (Not sure how) but whenever there is existing fragment in the backstack, the old UI is getting loaded. Can i refresh the layout here?</p>
  
  <pre><code>public void ReplaceFragment(Fragment fragment, FragmentManager fragmentManager)
          {
              string backStateName = fragment.Class.SimpleName;
              bool fragmentPopped = fragmentManager.PopBackStackImmediate(backStateName, 0);
  
              if (!fragmentPopped &amp;&amp; fragmentManager.FindFragmentByTag(backStateName) == null)
              {
                  fragmentManager.BeginTransaction()
                                 .Replace(Resource.Id.content_frame, fragment).SetTransitionStyle(FragmentTransaction.TransitFragmentFade)
                                 .AddToBackStack(backStateName)
                                 .Commit();
              }
  
          }
  </code></pre>
  
  <p>Can anyone please help me solve this any one of the above?</p>