Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9066697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:47:02+00:00 2026-06-16T16:47:02+00:00

My problem is the same as the one in the link below, but I

  • 0

My problem is the same as the one in the link below, but I couldn’t figure out the solution. And could not work out how to ask the author what his solution was.
Fragment with map crashes when I change activity and come back to the map

My app works fine until the orientation changes, Touch works beautiful up until that point. On orientation change it redraws the MapView as it should, but as soon as the user does any onTouch action on the map it crashes the app with:

android.view.WindowManager$BadTokenException error Unable to add window –token android.view.ViewRootImpl$blahblahblah is not valid.

I’m using ActionBarSherlock with the googlemaps plugin as suggested in the same tutorial the other question used. I just don’t get how I’m supposed to create a new listener for the onTouch event after the activity restarts on orientation change. I have tried just creating a new OnTouchListener to the onTouch event but as I’m unsure, and can’t find any examples, I haven’t been able to guess my way to get a working Touch interface on the MapView again.

I’m sure it’s something simple I’m missing.

The code I have:

public MainActivity extends SherlockFragmentActivity {
    private MapView mapView;
    private MapFragment mMapFragment;

    public void onCreate(Bundle savedInstanceState){
        View view = getLayoutInflater().inflate(R.layout.mapLayout, null);
        mapView = (MapView)view.findViewById(R.id.map);
        mapView.setBuiltInZoomControls(true);
        setContentView(R.layout.activity_main);
    }

    public void onResume(){
        setupFragments();
    }

    private void setupFragments(){
        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MapFragment.TAG);
        if (mMapFragment == null){
            mMapFragment = new MapFragment(mapView);
            ft.add(R.id.fragment_container, mMapFragment, MapFragment.TAG);
        }
        ft.show(mMapFragment);
        ft.commit();
    }
}

public class MapFragment extends SherlockFragment{
    public static final String TAG = "MapFragment";
    private MapView mapView;
    private MapOverlay itemizedOverlay;

    public MapFragment(MapView mapView){
        this.mapView=mapView;
    }

    public void onResume(){
        super.onResume();
        List<Overlay> mapOverlays = mapView.getOverlays();

        itemizedOverlay(defaultActiveRoad, mapView.getContext());
        mapOverlays.add(itemizedOverlay);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle savedInstanceBundle){
        super.onCreateView(inflater,vg,savedInstanceBundle);
        return mapView;
    }

    public void onViewCreated(View view, Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
    }

    public void onDestroyView(){
        super.onDestroyView();
        ((ViewGroup)mapView.getParent()).removeView(mapView);
    }

    public void setMapView (MapView mapView){
        this.mapView = mapView;
    }

    public MapView getMapView(){
        return mapView;
    }
}

The error log contains

android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@40fab3b0 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:585)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
at android.view.Window$LocalWindowManager.addView(Window.java:547)
at android.widget.ZoomButtonsController.setVisible(ZoomButtonsController.java:371)
at com.google.android.maps.MapView.displayZoomControls(MapView.java:1055)
at com.google.android.maps.MapView$1.onDown(MapView.java:341)
at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:517)
at com.google.android.maps.MapView.onTouchEvent(MapView.java:685)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:47:04+00:00Added an answer on June 16, 2026 at 4:47 pm

    After hitting my head against a wall for a few days, I decided to upgrade the map system to Google Maps Android API v2. This has solved the problem I was having with the zoom controls.

    After following the instructions on: Using ActionBarSherlock With the New SupportMapFragment

    I created a SherlockMapFragment as instructed in the instructions above, but in my app package. My MapFragment now extends the new SherlockMapFragment just created.

    public class MapFragment extends SherlockMapFragment {
    
    public static final String TAG = "MapFragment";
    private GoogleMap mapView;
    private Application global;
    public MapFragment(){
    }
    
    public void onCreate(Bundle savedInstanceBundle){
        super.onCreate(savedInstanceBundle);
        setRetainInstance(true);
    }
    
    public void onResume(){
        super.onResume();
    
        global = (Application)getSherlockActivity().getApplication();
    
    }
    
    public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle savedInstanceBundle){
        View view=super.onCreateView(inflater, vg, savedInstanceBundle);
        mapView = getMap();
        return view;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is basically the same than this one but on windows 7: How
I'm having the same problem issued in these two links: one , two .
We are facing one problem with DownloadStringCompleted method always returning same result in windows
I have the same problem described here on the e-office blog , but in
I just ran across a problem that took a little while to figure out
It seems like eveyone has this problem but no one has a laymans terms
im trying to have one link for a file download and at the same
One of the applications I work on has been spitting out ugly event log
I'm trying to get used to Ember.js and Handlebars, but one problem is puzzling
I'm having real headaches trying to work out a problem I have at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.