I have an inner class that loads a list that comes from the database, but in return of doInBackground
it returns the list empty.
I've already tested and for
is getting right, then populate the list, but when it gets down there it just returns empty.
After the background is executed, I need it delivered to onPostExecute
so that I can get the list as a result, ie there will be a method waiting for the list to be passed to the recycler.
public class CarregaLista extends AsyncTask<Void, String, List<DocumentSnapshot>> {
ProgressDialog dialog;
Context context;
public final String TAG = "documento exist";
public CarregaLista(Context ctx) {
this.context = ctx;
}
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(context);
dialog.setMessage("carregando lista...");
dialog.show();
}
@Override
protected List<DocumentSnapshot> doInBackground(Void... voidss) {
try {
mRefFirestore = FirebaseFirestore.getInstance();
mRefFirestore.collection("user")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
List<DocumentSnapshot> snapshots
= new ArrayList<DocumentSnapshot>();
for (DocumentSnapshot snapshot : task.getResult()) {
snapshots.add(snapshot);
}
documentSnapshot = snapshots;
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
Log.d("LOG", "><<<<<<<<><<<<<<" + documentSnapshot.size());
}
return documentSnapshot;
}
@Override
protected void onPostExecute(List<DocumentSnapshot> listaRecebida) {
pegaLista(documentSnapshot);
dialog.dismiss();
Log.d("LOG", "><<<<<<<<><<<<<<" + documentSnapshot.size());
}
}