I found the message Cannot resolve method 'getSupportFragmentManager ( )' I want to fragment as activity. because I want to use Maps on the tabs swipe.
public class PETAcikarangsukatani extends Fragment {
Context context;
private static final LatLng SUKATANI = new LatLng(-6.171327, 107.178108);
private static final LatLng WRPOJOK = new LatLng(-6.222411, 107.162158);
private static final LatLng PILAR = new LatLng(-6.257033, 107.156472);
private static final LatLng CIKARANG = new LatLng(-6.256073, 107.143984);
GoogleMap googleMap;
final String TAG = "PathGoogleMapActivity";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_path_google_map, container, false);
context = rootView.getContext();
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fm.getMap();
getSupportFragmentManager()
is not part ofFragment
, so you cannot get it here that way. You can get it from parentActivity
(so inonAttach()
the earliest) using normalor you can try getChildFragmentManager(), which is in scope of Fragment, but requires API17+
For my case, I made sure that Fragment class is imported from
Not from
Then I have used
And now its working. If I use activity instance which I got in onAttach() is not working also.
you should use
I have also this issues but resolved after adding
getActivity()
beforegetSupportFragmentManager
.Also you can use
AppCompatActivity
instead of Activity.Then
getSupportFragmentManager()
will work.And also not forget to make your App theme extend AppCompat theme in this case
just try this.it worked for my case
Extends FragmentActivity instead of Activity