aveschini
aveschini

Reputation: 1712

Android: two activities with two maps; the second one doesn't load properly

I try to explain better: My app has a tab bar (a TabHost) and two of the tabs are two activities with a map each. When i click on the first tab I get the map and i can use it as i want. When I click on the second one i get the SAME map, with the SAME markers and the same path drawn on it and I can't even move the map. I don't want it to act like that. Every activity has to use a different maps.

I am using v2 maps and the two activities extend android.support.v4.app.FragmentActivity.

Note that if I click on the second activity first, I can use the map as I want and the problem repeats on the first activity.

I am not reusing nothing! Everything has different names, ids, ecc...

Please help!

P.S. here is the code that i use to initialize the map (in one activity):

private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {

        Logger.log("mMap = null");

        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFollow))
                .getMap();

        mMap.getUiSettings().setCompassEnabled(false);

        mapContainer = getSupportFragmentManager().findFragmentById(R.id.mapFollow).getView();
        // Check if we were successful in obtaining the map.
        if (mMap == null) {
            //TODO: dialog error map.
        }
    }
}

EVERY time I switch between the two activities I get the "mMap = null" log...

Upvotes: 0

Views: 852

Answers (2)

aveschini
aveschini

Reputation: 1712

Searching all over the internet I found that this is a "bug" with the TabHost. The only way to make it work is to move one of the activities with the map in an "inner" place such as calling it via another "main" activity. In this way there will be only one activity with the map and the tabs together while the other activities with the map won't have the tabs. Not a good way but the only possible way for me.

Upvotes: 0

MaciejGórski
MaciejGórski

Reputation: 22232

The problem seems to be you are trying to put two SurfaceViews (map is drawn on this). ActivityGroup (TabActivity extends it) is long deprecated and you are better of switching to correct use of Fragments. Make a single FragmentActivity, which switches between two MapFragments.

Upvotes: 1

Related Questions