mercredi 11 mars 2015

Jumping at previous code without goto command



I have a news app which needs a refresh button


My code is something like this



private class GetContacts extends AsyncTask<Void, Void, Void> {

protected void onPreExecute() {
//something on UI
}

protected Void doInBackground(Void... arg0) {
restartfromhere:
//most of the networking is done here
// this is the part that I want to re-run to get new updates
}

protected void onPostExecute(Void result) {
//updates the data from internet in the application UI
}
}


Now i have a new button refresh, that needs to re-run the whole code again.


Like this, on refresh click



public void refresh(){
goto restartfromhere:
}


Java doesn't have goto command and I know that its bad programming practice. So, what is the alternative method I can use?




Aucun commentaire:

Enregistrer un commentaire