In one of my fragments, I save the clicked element:
private void saveFavorites(int position) { String name = personCategories.get(position); SharedPreferences sp = getActivity().getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putString("Favorites", name); editor.apply(); } After that, in another fragment I try to display the value that I saved, please tell me how you can display it, the code of the second fragment:
public class FavoritesFragment extends BaseFragment { TextView someText; public FavoritesFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.favorites_fragment, container, false); // someText.getText(getFavorites()); } private void getFavorites() { SharedPreferences sp = getActivity().getPreferences(Context.MODE_PRIVATE); String name = sp.getString("Favorites", null); }