What happens is that I have working on AndroidStudio, programming in Java where you have a function that makes data to a URL that I have, and upload some images, along with other data.
This process is all OK, what happens is that I have the problem that as the process is asynchronous it is finished after checking if all the images are uploaded.
What I have is the following code:
boolean ImgSubidasOK = true;
...
btnSubirFotosSistema.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
...
SubeFotografia(parametro1, parametro2);
if (ImgSubidasOK){
//hacerAlgo, ACTIVIDAD 1
}
else {
//hacerAlgo, ACTIVIDAD 2
}
...
}
}
...
public void SubeFotografia(final String parametro1, final String parametro2) {
...
PostResponseAsyncTask task = new PostResponseAsyncTask(MainActivity.this, postData, new AsyncResponse() {
@Override
public void processFinish(String s) {
if (s.contains("uploaded_success")){
//Subida exitosa imagen
}
else {
ImgSubidasOK = false;
//Error subida foto
}
}
});
String URLFinal = "https://URLASUBIRIMAGENES.php";
task.execute(URLFinal);
...
}
Then I would like that after running SubeFotografia (parametro1, parametro2); already have the final result of processFinish .
Because I have been given the case that there is a data upload error and it goes straight to if (ImgSubidasOK) and does ACTIVITY 1 as if everything had been fine, but really should enter < strong> else and do ACTIVITY 2.
This is because it first enters the if doing ACTIVITY 1 (because that value is true) and then a photo upload error occurs in the processFinish changing the value of ImgSubidasOK to false, but it's too late to verify.
And I need to finish first the SubeFotografia function, along with its asynchronous process, and AFTER to be able to continue with the code that follows (the verifications of if and else ImgSubidasOK)
The code simplifies it to show it here, but has more details that are not relevant. I would appreciate if someone could guide me how to solve that problem please.