In my AsyncTask I instantiate 4 new objects, but I have to stay in it until all objects are brought. Here is the code:
@Override
protected Void doInBackground(Void... voids) {
new CrtlComentario(contexto).trazer(post.getCodigo(), new CallbackTrazer() {
@Override
public void resultadoTrazer(Object obj) {
c = (Comentario) obj;
flag[3] = false;
}
@Override
public void falha() {
flag[3] = false;
}
});
new CrtlUsuario(contexto).trazer(c.getUsuarioPost(), new CallbackTrazer() {
@Override
public void resultadoTrazer(Object obj) {
u = (Usuario) obj;
flag[0] = false;
}
@Override
public void falha() {
flag[0] = false;
}
});
new CrtlComentarioPost(contexto).listar(new CallbackListar() {
@Override
public void resultadoListar(List<Object> lista) {
for (Object obj : lista)
cp.add((ComentarioPost) obj);
flag[1] = false;
}
@Override
public void falha() {
flag[1] = false;
}
});
new CrtlCurtidaComentario(contexto).listar(new CallbackListar() {
@Override
public void resultadoListar(List<Object> lista) {
for (Object obj : lista)
cc.add((CurtidaComentario) obj);
flag[2] = false;
}
@Override
public void falha() {
flag[2] = false;
}
});
return null;
}
The only objects that can never be null are the "c" and the "u" the other two can.
I need "c" to be loaded so I can load the other three because I need your code.
I tried to do a while to stay until they ended up using the variable flag [], but it does not work and sometimes does not even execute the task.