-
-
Save azumamagus/400d7a0a05c425a15a79b4eccbc75f0b to your computer and use it in GitHub Desktop.
EnviaDadosServidor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.ProgressDialog; | |
import android.content.Context; | |
import android.os.AsyncTask; | |
import android.widget.Toast; | |
import java.util.List; | |
import br.com.teste.agenda.WebClient; | |
import br.com.teste.agenda.converter.AlunoConverter; | |
import br.com.teste.agenda.dao.AlunoDAO; | |
import br.com.teste.agenda.modelo.Aluno; | |
public class EnviaDadosServidor extends AsyncTask<Void, String,String> { | |
private Context context; | |
private ProgressDialog alertDialog; | |
public EnviaDadosServidor(Context context){ | |
this.context = context; | |
} | |
@Override | |
protected void onPreExecute() { | |
super.onPreExecute(); | |
alertDialog = ProgressDialog.show(context,"Aguarde" , "Enviando para o servidor ...", true, true); | |
alertDialog.show(); | |
} | |
@Override | |
protected String doInBackground(Void... params) { | |
WebClient webClient = new WebClient(); | |
AlunoConverter converter = new AlunoConverter(); | |
AlunoDAO dao = new AlunoDAO(context); | |
List<Aluno> alunos = dao.buscaAlunos(); | |
dao.close(); | |
String json = converter.toJson(alunos); | |
String resposta = webClient.post(json); | |
return resposta ; | |
} | |
@Override | |
protected void onPostExecute(String resposta) { | |
alertDialog.dismiss(); | |
Toast.makeText(context, resposta, Toast.LENGTH_LONG).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment