[Solved] Navigating from an activity to a fragment [duplicate]


You can use from switching from Fragment to Activity-:

Implement this code on BackPressed-:

@Override
    public void onBackPressed() {
        super.onBackPressed();

     YourFragment mapFragment = new YourFragment();
    FragmentManager manager = getFragmentManager();
    manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit();
    }

While moving from Fragment to Activity-:

startActivity(new Intent(getActivity,YourActivity.Class));

and while moving from activity to Fragment-:

YourFragment mapFragment = new YourFragment();
FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit();

solved Navigating from an activity to a fragment [duplicate]