1

My application contains tab layout(TabHost, TabSpec).
I am using two map views in my application. So if I am enabling satellite view in one map_activity then go to the other map_activity then other map is also shown in satellite view, if I drag one map_activity towards USA other map view is also automatically dragged towards USA no matter where it was earlier pointing.

I general if we run two activity in different processes using android:process=":map1" and android:process=":map2" then we can solve the above problem. I referred here...

But how can we solve this problem in tab bar(TabHost, TabSpec) applications?

Community
  • 1
  • 1
AndroidDev
  • 2,627
  • 6
  • 29
  • 41
  • Your answering your own question. Look at the answer your referring too, two activities with each their map instance. Those activities are stored inside your tabs. – Warpzit Jun 11 '12 at 09:22
  • I know the link is a solution when you are starting activity using startActivity(intent). But this solution does not work when you are showing activities in tab(TabHost, TabSpec). – AndroidDev Jun 11 '12 at 09:30

1 Answers1

0

This is not a perfect solution, but it'll get the job done, sort off.

In those tabs where you need the mapview you create it in code:

    mMapView = new MapView(this, MAPS_KEY);
    mMapView.setClickable(true);
    LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mMapView.setLayoutParams(params);
    FrameLayout mapFrame = (FrameLayout) findViewById(R.id.map_container);
    mapFrame.addView(mMapView);

The xml is self explanatory (if not just request).

The problem with this approach is that when the mapview is instantiated it will remember the old position, so you need to move the map to the new position you want it to be at. Could be done like this:

mMapView.getController().animateTo(location);
                        mMapView.getController().setZoom(GlobalValues.EMERGENCY_MAP_ZOOM_LVL);
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • The map not just remembers the last position but also remembers last map mode i.e. map, satellite. We can directly use animateTo method to change the position of the map in new activity that is not a different map. – AndroidDev Jun 11 '12 at 12:58
  • No its not a different map, but you can use it across multiple activities. If you want a whole different map, the only solution I know of is the one you say doesn't work... – Warpzit Jun 11 '12 at 13:09
  • That solution works. I think startActivity(intent) method does all the magic. But not in tab bar application. When you select a particular tab(which has activity in manifest like android:process=":remote") you will be able to see in ddms that no separate process created for that. – AndroidDev Jun 11 '12 at 14:07