1
I have an Internet class that loads a list from the database, but on the return of the doInBackground
it returns the empty list.
I already tested and the for
is getting it right, then populates the list, but when it gets down there just returns it empty.
After the background run, I need it delivered to the onPostExecute
so I can get the list as a result, IE, there will be a method waiting for the list and pass 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());
}
}
Exchange for
pegaLista(listaRecebida);
– Piovezan
sorry didn’t understand
– luiz pinheiro de jesus
ah ok,then already I did not worked too,this is the problem the list arrives empty
– luiz pinheiro de jesus
So I don’t know, I’m going to owe. It would be nice to post the full code as suggested by the author of the reply.
– Piovezan