1
During an API interaction that lasts on average 5 seconds, I need to place a Process Dialog.
My code:
public class finalizaPedido extends AsyncTask<Object, Void, Integer> {
private String retorno;
private String url;
private String param = "?";
private View view;
public finalizaPedido(View v) {
view = v;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = ProgressDialog.show(getActivity(), "Loading...","Loading...");
}
@Override
protected void onPostExecute(Integer pedID) {
pd.dismiss();
view.getContext().startActivity(new Intent(view.getContext(), ActivityPedidoFinalizacao.class));
}
@Override
protected Integer doInBackground(Object... params) {
String lojaid = (String) params[0];
String carrinhoid = (String) params[1];
String formapagamento = (String) params[2];
String qtdparcela = (String) params[3];
String frete = (String) params[4];
String idbonus = (String) params[5];
String endid = (String) params[6];
String previsaoentrega = (String) params[7];
url = "http://xxx.xx.xxx.xx/JustForMoms/Pedido/FinalizaPedido/" + lojaid + "/" + carrinhoid + "/" + formapagamento + "/" + qtdparcela + "/";
param += "isApp=true";
if (!frete.equals("")) {
if (!param.equals("?")) param += "&";
param += "frete=" + frete;
}
if (!idbonus.equals("")) {
if (!param.equals("?")) param += "&";
param += "idbonus=" + idbonus;
}
if (!endid.equals("")) {
if (!param.equals("?")) param += "&";
param += "endid=" + endid;
}
if (!previsaoentrega.equals("")) {
if (!param.equals("?")) param += "&";
param += "previsaoentrega=" + previsaoentrega;
}
webclient client = new webclient(url.replace(" ", "%20") + param.replace(" ", "%20"));
retorno = client.getmodel();
if (retorno != null) {
try {
return Integer.parseInt(retorno);
} catch (Exception e){
Toast.makeText(getContext(), "Houve um problema na criação do seu pedido. Por favor tente novamente e caso o problema persistir, entre em contato com a Equipe do Blubalu.", Toast.LENGTH_LONG);
}
}
return 0;
}
}
I happen to click the button that calls the task, but the process dialog does not appear. It is only when the request ends, and already redirects to the next page.
For security reasons should not put the IP.
– ramaral