Search code examples
androidandroid-fragmentsmapboxmapbox-androidsupportmapfragment

How to use mapbox SupportMapFragment to dynamically add map on an another activity Android


How can I use this sample code: https://docs.mapbox.com/android/legacy/maps/examples/support-map-fragment/ for my app? this sample code extends AppCompatActivity instead of it being a Fragment so I can't add it on my navigation activity that has the layout for my bottom navigation bar and the FragmentManager.

Overall, what I want to achieve is a bottom navigation bar that could dynamically add and replace the map fragment with other fragments any examples would be appreciated. I've read the mapbox docs fragment examples but I don't know how to apply them for my use case.

Using the said example, can I just return a SupportMapFragment instance on my class using a getter function so that it could be used by the FragmentManager of my navigation activity?


Solution

  • Solved this by extending Fragment instead of AppCompatActivity and just replacing Activity lifecycle methods like onCreated to onViewCreated and using requireActivity() for any arguments requiring the activity context.