user3188040
user3188040

Reputation: 711

any advantages/disadvantages in google maps v2 using a MapView object inside a Fragment versus a MapFragment in a Fragment?

I have an android app that is using a sliding drawer with a framelayout to hold a details view. On selection of an item in the drawer, the main activity replaces fragments in the framelayout using a call like...

FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

To show google maps v2 in the fragment, I've had to define a MapView inside a Fragment in order to get the replace call to work correctly.

Now that's one way to implement it, I could also have defined a MapFragment inside a Fragment using the new nested fragments capability. So given that in the future I want to add icons and control the map from code, which approach is better and why?

Upvotes: 1

Views: 694

Answers (1)

King of Masses
King of Masses

Reputation: 18775

MapFragment

  • Use it if you want to add a map into Activity class (not fragment because it will create a nested fragment and it´s a mess).
  • Use SupportMapFragment if you want to support just android versions lower than v12.

MapView

  • Use it if you are going to add a map into a fragment. (you need to update each lifecicle to MapView).

In your case as your using the fragment it is better to use the map view. That way you will avoid cascading fragments when you don't have to.

Upvotes: 2

Related Questions