package com.example.myapp_2;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import com.example.myapp_2.List_1.Product;
import com.example.myapp_2.List_1.ProductAdapter;

import java.util.Collections;
import java.util.List;

public class SortWorker extends Worker {

    private ProductAdapter adapter;

    public SortWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        adapter.sortProductsByPrice();
        return Result.success();
    }

   // public SortWorker() {
        //super();
    //}
    public SortWorker(@NonNull Context context) {
        super(context, null);
    }

    public void setAdapter(ProductAdapter adapter) {
        this.adapter = adapter;
    }
}  (Код активации в фрагменте:  SortWorker worker = new SortWorker(getContext());
        worker.setAdapter(productAdapter);
        OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SortWorker.class).build();
        WorkManager.getInstance(getContext())
                .beginUniqueWork("SortProducts", ExistingWorkPolicy.REPLACE, request)
                .enqueue();) (Возникла ошибка : E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapp_2, PID: 1793
    java.lang.IllegalArgumentException: WorkerParameters is null
        at androidx.work.ListenableWorker.<init>(ListenableWorker.java:81)
        at androidx.work.Worker.<init>(Worker.java:51)
        at com.example.myapp_2.SortWorker.<init>(SortWorker.java:33)
        at com.example.myapp_2.UI.view.fragments.SecondFragment.onCreateView(SecondFragment.java:103)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963 исправт эту ошибку)