In the documentation for MapFragment
and SupportMapFragment
they create a new fragment by calling newInstance()
instead of using new SupportMapFragment()
.
My app project extends SupportMapFragment
, and I tried to call MyMapFragment.newInstance()
on my fragment class, resulting in the map showing up as expected but none of my overridden methods such as onCreateView()
and onActivityCreated()
were being called. Took me a while before I tried instantiating my fragment by using new MyMapFragment()
instead - and voíla, my overridden methods started getting called!
I didn't override newInstance()
in my class, and in hindsight it's obvious that newInstance()
returns an instance of SupportMapFragment
, not an instance of my extended class (duh!).
But my question is - why is there a newInstance()
method and why does the documentation use it, when it seems to work just as well using new SupportMapFragment()
? What's the difference of using one or the other? I haven't been able to find the source code for SupportMapFragment, so...