title: Fragment with map crashes when I change activity and come back to the map
body: <p>I have an app with a few activities, but in each activity I've got some fragments. The layout of the activity has a RelativeLayout as a Fragment Container. I have added tabs navigation with ActionBarSherlock and a tab is to watch a map. </p>
  
  <p>I have used MapViewBalloons library. When I click in a tab I replace the fragment with the corresponding fragment. </p>
  
  <p>In the Map Fragment I have used a static variable to save my mapView object not to create a new one each time I access to this fragment. </p>
  
  <p>I can enter to the map fragment, move it there, touch and move the map. Then change to another fragment with a tab, WITHOUT changing the activity, and I still have the same map, the same situation and I can navigate there.</p>
  
  <p>THE PROBLEM: If I press back button, if I change orientation (I guess, if the activity is destroyed and re-created) I can enter again to the map, but if I try to move there it crashes and I've got this error:</p>
  
  <p>Unable to add Window, token android.view.ViewRootImpl$... is not valid, is your activity running?</p>
  
  <pre><code>static TapControlledMapView mapView;
  onCreateView...
  if (mapView == null) {
  //do things
  else 
  parentViewGroup.removeView(mapView);
          Button botonFiltro = (Button) parentViewGroup
                  .findViewById(R.id.botonFiltro);
          parentViewGroup.removeView(botonFiltro);
          inf.addView(mapView);
  return inf;
  </code></pre>
  
  <p>That's how I handled the "you are only allowed to have a single map" stuff. </p>
  
  <p>So... Why crashes if I change activity? I have checked that parentViewGroup is not null, so MapView have a parent (I don't know if this have any sense). </p>
  
  <p>My TabListener is like that;</p>
  
  <p>public class MyTabListener implements TabListener {</p>
  
  <pre><code>public Fragment fragment;
  
  public MyTabListener(Fragment fragment) {
      super();
      this.fragment = fragment;
  }
  
  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
      //TODO: onTabReselected
  }
  
  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {        
      ft.replace(R.id.fragmentContainer, fragment);
  }
  
  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
      ft.remove(fragment);
  }
  </code></pre>
  
  <p>The strangest thing is that if I don't touch the map the first time I get in, or the second time, it doesn't crash. </p>
  
  <p>I'm new in Android so maybe I'm not doing things correct. Can anybody help me?</p>
  
  <p>EDIT: I have used another library to make compatible ABS, Fragments and the Map. I have followed this blog: <a href="http://xrigau.wordpress.com/2012/03/22/howto-actionbarsherlock-mapfragment-listfragment/" rel="nofollow">http://xrigau.wordpress.com/2012/03/22/howto-actionbarsherlock-mapfragment-listfragment/</a></p>
  
  <p>FIXED! The problem was the one that I talkted about in the comment. The listener was attached to the old activity. Add new listener and done!</p>