I'm trying to make a fragment so that if it has been opened before stay on the same page or if not go to a different fragment. It seems that anything I've tried doesn't work. Please Help.
My Code:
public class PreferencesView extends Fragment {
public static boolean Preferences_Opened = false;
public void changePreferences() {
if (!Preferences_Opened) {
PreferencesChange newFragment = new PreferencesChange();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace((What am I supposed to put here?), newFragment);
transaction.addToBackStack(null);
transaction.commit();
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.activity_preferences_view, container, false);
changePreferences();
//Other non-important stuff here
return rootView;
}
}