I'm using Retrofit2 and DBFlow. I have a problem when I save my data into my database. Certain data are duplicated when I'm calling the thread twice at the same time. The problem is my List because this variable is final. And I have to set final because I need to use this List in my thread.
Then, there is a way to remove the final to my List and replace by something ?
Retrofit onResponse()
public void onResponse(Call<AdminPictures> call, Response<AdminPictures> response) {
AdminPictures apResponse = response.body();
// Here is my list
final List<PictureInfos> pictureInfos = apResponse.getPicturesList();
new Thread(new Runnable() {
@Override
public void run() {
try {
// The List is used here
for (PictureInfos infos : pictureInfos) {
if(!infos.exists()){
infos.save();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();