Для того, чтобы сохранить оценки товаров в SharedPreferences и восстановить их после перезапуска приложения, необходимо использовать методы SharedPreferences.Editor, а также onSaveInstanceState и onViewStateRestored. Измененный код может выглядеть так:

public class FirstFragment extends Fragment {

private RecyclerView recyclerView;
private ProductAdapter productAdapter;
private ViewPager viewPager;
private List<String> imageUrls = Arrays.asList(
“https://image_url_1”,
“https://image_url_2”,
“https://image_url_3”
);
private List<Product> products = getProducts();

private static final String MY_PREFS_NAME = “MyPrefs”;
private float rating1 = 0.0f;
private float rating2 = 0.0f;
private float rating3 = 0.0f;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_first, container, false);

recyclerView = v.findViewById(R.id.recycler_view_products);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
productAdapter = new ProductAdapter(getContext(), products);
recyclerView.setAdapter(productAdapter);

viewPager = v.findViewById(R.id.view_pager);
SliderAdapter adapter = new SliderAdapter(getActivity(), imageUrls);
viewPager.setAdapter(adapter);

// Получаем оценки из SharedPreferences
SharedPreferences prefs = getContext().getSharedPreferences(MY_PREFS_NAME, Context.MODE_PRIVATE);
rating1 = prefs.getFloat(“rating1”, 0.0f);
rating2 = prefs.getFloat(“rating2”, 0.0f);
rating3 = prefs.getFloat(“rating3”, 0.0f);

// Устанавливаем оценки в соответствующие товары
products.get(0).setRating(rating1);
products.get(1).setRating(rating2);
products.get(2).setRating(rating3);

final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
int currentItem = viewPager.getCurrentItem();
int totalItems = viewPager.getAdapter().getCount();
int nextItem = currentItem == totalItems - 1 ? 0 : currentItem + 1;
viewPager.setCurrentItem(nextItem);
handler.postDelayed(this, 3000);
}
};
handler.postDelayed(runnable, 3000);

return v;
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
// Сохраняем оценки в Bundle
outState.putFloat(“rating1”, rating1);
outState.putFloat(“rating2”, rating2);
outState.putFloat(“rating3”, rating3);
}

@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
// Восстанавливаем оценки из Bundle
rating1 = savedInstanceState.getFloat(“rating1”);
rating2 = savedInstanceState.getFloat(“rating2”);
rating3 = savedInstanceState.getFloat(“rating3”);

// Устанавливаем оценки в соответствующие товары
products.get(0).setRating(rating1);
products.get(1).setRating(rating2);
products.get(2).setRating(rating3);
}
}

@Override
public void onPause(){
super.onPause();
// Сохраняем оценки в SharedPreferences
SharedPreferences.Editor editor = getContext().getSharedPreferences(MY_PREFS_NAME, Context.MODE_PRIVATE).edit();
editor.putFloat(“rating1”, products.get(0).getRating());
editor.putFloat(“rating2”, products.get(1).getRating());
editor.putFloat("rating3