title: Android - Handing Fragments during Backpress
body: <p>I have,   <code>Fragment A</code> that contains <em>listView</em> - by the time the user clicks an item the current view will be replaced by  another view that also contains a listview called <code>Fragment B</code>. </p>
  
  <p>Fragment A -> B, I manage to add Fragment A to backstack so when the user is in <code>Fragment B</code>, if he press the back button it will go back to <code>Fragment A</code>. The problem is after I press Again <code>Fragment A</code>(<em>listView</em>) it will just display a bank screen and I expect that <code>Fragment B</code> should be displayed again.</p>
  
  <p><strong>Fragment A</strong></p>
  
  <pre><code>      lv.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
  
  
                  //FragmentActivity  activity =  getActivity();
  
                      String fragMainGroups = "mainGroups";
  
                      Fragment videoFragment = new VideoPlayerFragment();
                      FragmentTransaction transaction = getFragmentManager().beginTransaction();
                      transaction.replace(R.id.contentFragment, videoFragment, fragMainGroups );
                      transaction.addToBackStack(fragMainGroups);
                      transaction.commit(); 
  
              }
          });
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>                String fragMainGroups = "mainGroups";
              String Groups = "Groups";
  
                  Fragment fragment1 = new VideoPlayerFragment();
  
  
                  /*FragmentTransaction transaction = getFragmentManager().beginTransaction();
                  transaction.replace(R.id.contentFragment, fragment1, fragMainGroups );
                  transaction.addToBackStack(fragMainGroups);
                  transaction.commit(); */
  
                  FragmentTransaction ft = getFragmentManager().beginTransaction();
                  ft.addToBackStack(Groups);
                  ft.add(R.id.contentFragment, fragment1, fragMainGroups);
                  ft.commit();
  </code></pre>