i'm working on an app in which i'm getting data from rest api , so basically i implemented WorkManager for that and i want the data to refresh every 15 minutes , so i set the minimum value for interval as 15 minutes , i set up my workmanager class in which i make a request to my api , and passed that class to PeriodicTimeRequest , now i dont know how i'm going to set the data to my recyclerview after initiating the request
this is my WorkManager Class
public class WorkManager extends Worker {
public static List<Movie> list;
public WorkManager(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result doWork() {
getData();
return Result.success();
}
public void getData() {
RetrofitBuilder.getData().getTopRatedMovies(Utils.apikey, Utils.language, 1)
.enqueue(new Callback<Movie>() {
@Override
public void onResponse(Call<Movie> call, Response<Movie> response) {
if (response.isSuccessful()) {
list = response.body().getMovies();
}
}
@Override
public void onFailure(Call<Movie> call, Throwable t) {
Log.d("TODO", "Excep" + t.toString());
}
});
}
this is my PeriodicTimeRequest in my activity
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(WorkManager.class,
15, TimeUnit.MINUTES)
.setConstraints(constraints)
.build();
androidx.work.WorkManager.getInstance(MainActivity.this).enqueueUniquePeriodicWork("tags",
ExistingPeriodicWorkPolicy.KEEP,periodicWorkRequest);
so i basically want to update data from api every 15 minutes , and then i want to get data and push it to my recyclerview , am i using the right approach for that , thank you guys .