0

I am using google map v2 in my application, but when I try to create a object for SupportMapFragment with onActivityCreated() this method is not getting called somebody please help me Here is my code,

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        super.onCreateView(inflater, container, savedInstanceState);
        Log.d("err", "onCreateView");
        view = inflater
                .inflate(R.layout.todays_deal_location, container, false);
    mFragment = new SupportMapFragment() {
                 @Override
                 public void onActivityCreated(Bundle savedInstanceState) {
                 super.onActivityCreated(savedInstanceState);
                 Log.d("err", "onActivityCreated");
                 GoogleMap map = mFragment.getMap();
                 }
                 };
       return view;
}
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
Sreedhu Madhu
  • 2,480
  • 2
  • 30
  • 40

2 Answers2

0

You should know the lifecycle of the Fragments and also the purpose the onCreateView() and onActivityCreated() methods in `Fragments.

onCreateView():

Here we inflate the layout or simply create the view and further if you have to do anything that takes reference to Activity don’t do it like creating dialogs,accessing views of Activity etc because,this place doesn’t ensure that hosting Activity is fully functional

onActivityCreated():

This method place signifies that our hosting Activity views are created and hosting Activity is functional and this is the right place to do all your Activity related task.

onActivityCreated() Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state. It is also useful for fragments that use setRetainInstance(boolean) to retain their instance, as this callback tells the fragment when it is fully associated with the new activity instance. This is called after onCreateView(LayoutInflater, ViewGroup, Bundle) and before onStart().

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0

This is how to add SupportMapFragment to your fragment correctly:

http://code.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1

Note:

  1. R.layout.layout_with_map doesn't contain fragment
  2. using getChildFragmentManager()
MaciejGórski
  • 22,187
  • 7
  • 70
  • 94