1
I am using Asynctask in my project and ended up generating a doubt in the passage of variables, in the method doInBackground
i return a cursor variable that is passed by Return. I wanted to know what is required to use Return, because if I pass Return as null I can still use my variable in the method onPostExecute
. I can do the same example below:
public class SearchGeocode extends AsyncTask<String, Integer, Cursor> {
public Cursor minhaVariavel;
public Boolean verifica;
protected Cursor doInBackground(String... countryTitle) {
minhaVariavel = SqliteDatabase;
verifica = false;
return null;
}
protected void onPostExecute(Cursor cursort) {
super.onPostExecute(cursort);
adapSerchView = new AdapSerchView(context, minhaVariavel, 0);
if (verifica){
//Faça Algo
}
}
}
Another thing in the onPostExecute method I can call again the same Asynctask?
– Stênio Barroso de Moraes
It depends. Only if it is another instance, the same instance is only executed once. But think about whether this is what you need, because wanting to run two Asynctasks in sequence may be indicative of having a wrong implementation intention (for example, you could rework this to use only one Asynctask instead).
– Piovezan
Yes I understand. Thank you.
– Stênio Barroso de Moraes