0

I simply have 2 tabs and used as reference from Experience - Multiple Android Activities in a TabActivity My class Architecture is like this:
MainActivity extends TabActivity
1.TabGroup1Activity extends TabGroupActivity (TabGroupActivity-class implemented from above reference)
1.i. Tab1Activity extends MapActivity (which has multiple marker)
2.TabGroup2Activity extends TabGroupActivity
2.i. Tab2Activity

MainActivity.java

TabHost = getTabHost();
    Intent intentTab;
    intentTab = new Intent().setClass(this, TabGroup1Activity.class);
    mTabHost.addTab(mTabHost.newTabSpec("tab_1").setIndicator("Search")
            .setContent(intentTab));

    intentTab = new Intent().setClass(this, TabGroup2Activity.class);
    mTabHost.addTab(mTabHost.newTabSpec("tab_2").setIndicator("Google Map")
            .setContent(intentTab));
TabHost.setCurrentTab(0);

TabGroup2Activity.java

public class GroupTab2Activity extends TabGroupActivity{
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startChildActivity("Tab2Activity", new Intent(this,Tab2Activity.class));


    }

}

In Tab2Activity.java, i have a button named googleMapButton.

googleMapButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {            

            final Intent intent = new Intent(Intent.ACTION_VIEW, Uri
                    .parse("http://maps.google.com/maps?"
                            + "saddr=43.0054446,-87.9678884"
                            + "&daddr=42.9257104,-88.0508355"));

            intent.setClassName("com.google.android.apps.maps",
                    "com.google.android.maps.MapsActivity");
            startActivity(intent);

        }
    });

On clicking the button,it loads the native google map but tab at bottom disappears, How can i make it to open in same tab ??
Thanx !!

captaindroid
  • 2,868
  • 6
  • 31
  • 45

1 Answers1

1

Take a look here:

googleMapButton.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {            

        final Intent intent = new Intent(Intent.ACTION_VIEW, Uri
                .parse("http://maps.google.com/maps?"
                        + "saddr=43.0054446,-87.9678884"
                        + "&daddr=42.9257104,-88.0508355"));

        intent.setClassName("com.google.android.apps.maps",
                "com.google.android.maps.MapsActivity");
        startActivity(intent);

    }
});

What you are doing is firing explicit intent to Google Maps application("com.google.android.apps.maps") installed on the device, asking it to run MapsActivity. Once this is fired, it leaves your application and runs Google Map.

If you wish to open up Google Map in your own application, you have to do it by yourself. This would be a good start for you: http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.html

RobGThai
  • 5,937
  • 8
  • 41
  • 59
  • I only successfully opened map in WebView if I host the Map on the server myself (instruction on Google Map API page). I have tried the iOS approach of using built-in browser to open Map, but I wasn't able to make it work. If you insisted to try it then good luck to you. I'm now used to using MapView and it's quite handy. – RobGThai Apr 09 '12 at 19:01
  • can i get ur one of ur sample project on MapView showing direction between two directions ?? github, svn ?? – captaindroid Apr 10 '12 at 01:06
  • I used the one from the link in my answer. Then I use this to parse KML file. http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/8880716#8880716 – RobGThai Apr 10 '12 at 03:46