I found the message Cannot resolve method \'getSupportFragmentManager ( )\' I want to fragment as activity. because I want to use Maps on the tabs swipe.
pub
you should use
getActivity.getSupportFragmentManager() like
//in my fragment
SupportMapFragment fm = (SupportMapFragment)
getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
I have also this issues but resolved after adding getActivity() before getSupportFragmentManager.
getSupportFragmentManager() is not part of Fragment, so you cannot get it here that way. You can get it from parent Activity (so in onAttach() the earliest) using normal
activity.getSupportFragmentManager();
or you can try getChildFragmentManager(), which is in scope of Fragment, but requires API17+
For me I made sure to import v4 like this:
import android.support.v4.app.DialogFragment;
Then used:
getActivity().getFragmentManager()
If you're instantiating an android.support.v4.app.Fragment class, the you have to call getActivity().getSupportFragmentManager() to get rid of the cannot-resolve problem. However the official Android docs on Fragment by Google tends to over look this simple problem and they still document it without the getActivity() prefix.
For my case, I made sure that Fragment class is imported from
android.support.v4.app.Fragment
Not from
android.app.Fragment
Then I have used
getActivity().getSupportFragmentManager();
And now its working. If I use activity instance which I got in onAttach() is not working also.
Inside a Fragment subclass you have to use getFragmentManager in place of getSupportFragmentManager. You will get the support one if the import are from the support library.