Execute various methods within AsyncSatck

1

I'm developing an app for android, which sends me a webervices and consuming it by kSoap, I'm already in the final process of the app, I'm in the engraving part, in which when the user TAP in the option to save this has to do a second process in which you have to make a call to the webservices to send the information collected and save it in the system.

The detail is that good to record first I have to call a method called getrecurso which this gives me id, I have another method that I have call called FillFill and another more FillDetail, my question or where I am stuck, is to know if I can make a second call within the same Asynstack ... for example when I make the call to get a record and that id is saved and in that same thread I can call the webservices to my second meter that would be FillIncarbezado, I do not know if you can explain me how to do it, I leave my code to you

Webservices methods

GetResource

 public static int ObtenerRecurso()
    {

        // Create request
        SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9020/","ObtenerRecurso");
        // Property which holds input parameters

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.implicitTypes=false;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);

        try {
            androidHttpTransport.debug = true;
            // Invoke web service
            androidHttpTransport.call("http://oncontrol.no-ip.net:9020/ObtenerRecurso", envelope);
            String ss = androidHttpTransport.responseDump;
            SoapObject response = (SoapObject) envelope.getResponse();

        }
        catch (Exception e) {
            //Assign Error Status true in static variable 'errored'
            //menu.errored = true;
            e.printStackTrace();
        }


        return Integer.parseInt(null);
    }

Top-Fill Method

 public static void LLenarEncabezadoCXCP(int Recurso,
                                            String Accion,
                                            int Id,
                                            int Empresa,
                                            String Folio,
                                            Date Fecha,
                                            int Cliente,
                                            int Proveedor,
                                            int Moneda,
                                            double TipoCambio,
                                            int BancoCuenta,
                                            String UsuarioCaptura,
                                            int PagoForma,
                                            double Saldo,
                                            double Importe,
                                            double Financiamiento,
                                            double Descuento,
                                            double SubTotal,
                                            double Retencion1,
                                            double Retencion2,
                                            double IEPS,
                                            double IVA,
                                            double ISH,
                                            double Total,
                                            double TotalAplicado,
                                            String Status,
                                            String UsuarioCancela,
                                            double Numero1,
                                            double Numero2,
                                            double Numero3,
                                            double Numero4,
                                            double Numero5,
                                            double Numero6,
                                            double Numero7,
                                            double Numero8,
                                            double Numero9,
                                            double Numero10,
                                            String Texto1,
                                            String Texto2,
                                            String Texto3,
                                            String Texto4,
                                            String Texto5,
                                            String Texto6,
                                            String Texto7,
                                            String Texto8,
                                            String Texto9,
                                            String Texto10,
                                            Date Fecha1,
                                            Date Fecha2,
                                            Date Fecha3,
                                            Date Fecha4,
                                            Date Fecha5,
                                            Date Fecha6,
                                            String Observaciones,
                                            int Concepto,
                                            String ObservacionCancelacion,
                                            int OrigenVentaCompra,
                                            int OrigenInventario)
    {
        // Create request
        SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9020/","LLenarEncabezadoCXCP");
        request.addProperty("Recurso",Recurso);
        request.addProperty("Accion"," ");
        request.addProperty("Id", "");
        request.addProperty("Empresa","");
        request.addProperty("Folio", "");
        request.addProperty("Fecha"," ");
        request.addProperty("Cliente"," ");
        request.addProperty("Proveedor","");
        request.addProperty("Moneda"," ");
        request.addProperty("TipoCambio"," ");
        request.addProperty("BancoCuenta"," ");
        request.addProperty("UsuaurioCaptura","");
        request.addProperty("PagoForma","");
        request.addProperty("Saldo","");
        request.addProperty("Importe","");
        request.addProperty("Financiamiento","");
        request.addProperty("Descuento","");
        request.addProperty("SubTotal","");
        request.addProperty("Retencion2","");
        request.addProperty("Retencion2","");
        request.addProperty("IEPS","");
        request.addProperty("IVA","");
        request.addProperty("ISH","");
        request.addProperty("Total","");
        request.addProperty("TotalAplicado","");
        request.addProperty("Status","");
        request.addProperty("UsuarioCancela","");
        request.addProperty("Numero1","");
        request.addProperty("Numero2","");
        request.addProperty("Numero3","");
        request.addProperty("Numero4","");
        request.addProperty("Numero5","");
        request.addProperty("Numero6","");
        request.addProperty("Numero7","");
        request.addProperty("Numero8","");
        request.addProperty("Numero9","");
        request.addProperty("Numero10","");
        request.addProperty("Texto1","");
        request.addProperty("Texto2","");
        request.addProperty("Texto3","");
        request.addProperty("Texto4","");
        request.addProperty("Texto5","");
        request.addProperty("Texto6","");
        request.addProperty("Texto7","");
        request.addProperty("Texto8","");
        request.addProperty("Texto9","");
        request.addProperty("Texto10","");
        request.addProperty("Fecha1","");
        request.addProperty("Fecha2","");
        request.addProperty("Fecha3","");
        request.addProperty("Fecha4","");
        request.addProperty("Fecha5","");
        request.addProperty("Fecha6","");
        request.addProperty("Observacion","");
        request.addProperty("Catalogo1","");
        request.addProperty("Catalogo2","");
        request.addProperty("Catalogo3","");
        request.addProperty("Catalogo4","");
        request.addProperty("Catalogo5","");
        request.addProperty("Catalogo6","");
        request.addProperty("OrdenCompra","");
        request.addProperty("Concepto","");
        request.addProperty("ObservacionCancelacion","");
        request.addProperty("OrigenVentaCompra","");
        request.addProperty("OrigenInventario","");


        // Property which holds input parameters

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.implicitTypes=false;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);

        try {
            androidHttpTransport.debug = true;
            // Invoke web service
            androidHttpTransport.call("http://oncontrol.no-ip.net:9020/LLenarEncabezadoCXCP", envelope);
            String ss = androidHttpTransport.responseDump;
            SoapObject response = (SoapObject) envelope.getResponse();

        } catch (SoapFault soapFault) {
            soapFault.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return;
    }

Method Fill detail

    public static String LLenarDetalleCXCP(int Recurso,
                                                String Accion,
                                                int Id,
                                                int Origen,
                                                int OrigenDocumento,
                                                double Importe,
                                                double Financiamiento,
                                                double Descuento,
                                                double SubTotal,
                                                double Retencion1,
                                                double Retencion2,
                                                double IEPS,
                                                double IVA,
                                                double ISH,
                                                double Total,
                                                double Saldo,
                                                String Referencia)
         {

             SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9020/","ObtenerRecurso");
             request.addProperty("Recurso","");
             request.addProperty("Accion","");
             request.addProperty("Id","");
             request.addProperty("Origen","");
             request.addProperty("OrigenDocumento","");
             request.addProperty("Importe","");
             request.addProperty("Financiamiento","");
             request.addProperty("Descuento","");
             request.addProperty("SubTotal","");
             request.addProperty("Retencion1","");
             request.addProperty("Retencion2","");
             request.addProperty("IEPS","");
             request.addProperty("IVA","");
             request.addProperty("ISH","");
             request.addProperty("Total","");
             request.addProperty("Saldo","");
             request.addProperty("Referencia","");
             // Property which holds input parameters

             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.dotNet = true;
             envelope.implicitTypes=false;
             // Set output SOAP object
             envelope.setOutputSoapObject(request);
             // Create HTTP call object
             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);

             try {
                 androidHttpTransport.debug = true;
                 // Invoke web service
                 androidHttpTransport.call("http://oncontrol.no-ip.net:9020/LLenarEncabezadoCXCP", envelope);
                 String ss = androidHttpTransport.responseDump;
                 SoapObject response = (SoapObject) envelope.getResponse();

             } catch (SoapFault soapFault) {
                 soapFault.printStackTrace();
             } catch (XmlPullParserException e) {
                 e.printStackTrace();
             } catch (IOException e) {
                 e.printStackTrace();
             }

             String resultado = null;
             return resultado ;
         }

code button

         Button pagar = (Button)this.findViewById(R.id.btnpago);
                pagar.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v)
                    {

                        AsyncGrabarCXCP task = new AsyncGrabarCXCP();
                        //Call execute
                        task.execute();
        }

});

class asyn to record

public class AsyncGrabarCXCP extends AsyncTask     {         int Resource;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        dialog=new ProgressDialog(Detalle_Cliente.this);
        dialog.setIndeterminate(false);
        dialog.setMessage("Guardando Datos...");
        dialog.setCancelable(false);
        dialog.show();
    }

    @Override
    protected Integer doInBackground(Void... params) {
        Recurso=webService.ObtenerRecurso();
        Recurso=webService.LLenarEncabezadoCXCP(recurso,accion,id,empresa,folio,fecha,cliente,proveedor,moneda,tipoCambio,bancocuenta,
                                                usuariocaptura,pagoforma,saldo,importe,financiamiento,descuento,subtotal,retencion1,retencion2,
                                                ieps,iva,ish,total,totalaplicado,status,usucariocancela,numero1,numero2,numero3,numero4,numero5,
                                                numero6,numero7,numero8,numero9,numero10,texto1,texto2,texto3,texto4,texto5,texto6,texto7,
                                                texto8,texto9,texto10,fecha1,fecha2,fecha3,fecha4,fecha5,fecha6,observaciones,concepto,observacioncancelacion,
                                                origeninventario,origeninventario);
        Recurso=webService.LLenarDetalleCXCP(_recurso,accion,id,origen,origendocumento,importe,financiamiento,descuento,subtotal,retencion1,retencion2,ieps,
                                              iva,ish,total,saldo,refencia);
        return Integer.valueOf("");
    }


    @Override
    protected void onPostExecute(Integer integer) {
        super.onPostExecute(integer);
    }
}

The logcat stacktrace

errro Logcat

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
                                                                                  Process: mx.com.oncontrol.oncontrolmovile, PID: 23061
                                                                                  java.lang.RuntimeException: An error occured while executing doInBackground()
                                                                                      at android.os.AsyncTask$3.done(AsyncTask.java:300)
                                                                                      at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                                                                                      at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
                                                                                      at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                                      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                                      at java.lang.Thread.run(Thread.java:841)
                                                                                   Caused by: java.lang.NumberFormatException: Invalid int: ""
                                                                                      at java.lang.Integer.invalidInt(Integer.java:137)
                                                                                      at java.lang.Integer.parseInt(Integer.java:358)
                                                                                      at java.lang.Integer.parseInt(Integer.java:331)
                                                                                      at java.lang.Integer.valueOf(Integer.java:489)
                                                                                      at mx.com.oncontrol.oncontrolmovile.Detalle_Cliente$AsyncGrabarCXCP.doInBackground(Detalle_Cliente.java:224)
                                                                                      at mx.com.oncontrol.oncontrolmovile.Detalle_Cliente$AsyncGrabarCXCP.doInBackground(Detalle_Cliente.java:199)
                                                                                      at android.os.AsyncTask$2.call(AsyncTask.java:288)
                                                                                      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
                                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                                                                                      at java.lang.Thread.run(Thread.java:841) 
05-09 19:41:30.417 23061-23061/mx.com.oncontrol.oncontrolmovile E/WindowManager: android.view.WindowLeaked: Activity mx.com.oncontrol.oncontrolmovile.Detalle_Cliente has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{52ac37e4 V.E..... R......D 0,0-684,192} that was originally added here
                                                                                     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
                                                                                     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
                                                                                     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
                                                                                     at android.app.Dialog.show(Dialog.java:286)
                                                                                     at mx.com.oncontrol.oncontrolmovile.Detalle_Cliente$AsyncGrabarCXCP.onPreExecute(Detalle_Cliente.java:210)
                                                                                     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
                                                                                     at android.os.AsyncTask.execute(AsyncTask.java:535)
                                                                                     at mx.com.oncontrol.oncontrolmovile.Detalle_Cliente$1.onClick(Detalle_Cliente.java:77)
                                                                                     at android.view.View.performClick(View.java:4438)
                                                                                     at android.view.View$PerformClick.run(View.java:18422)
                                                                                     at android.os.Handler.handleCallback(Handler.java:733)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                     at android.os.Looper.loop(Looper.java:136)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                                     at dalvik.system.NativeStart.main(Native Method)
    
asked by Hugo Rodriguez 09.05.2016 в 19:16
source

1 answer

1

Instead of creating several AsyncTask , within your AsyncTask

 AsyncGrabarCXCP task = new AsyncGrabarCXCP();
            //Call execute
            task.execute();

you can add the 3 methods to be executed sequentially:

@Override
protected Void doInBackground(String... params) {
    ObtenerRecurso();
   LLenarEncabezadoCXCP();
   LLenarDetalleCXCP();
    return "";
}

I see that your method LLenarDetalleCXCP() , does not make modifications to the UI, if you add that code later, remember that the operations to modify your UI can be done within onPostExecute() ,

------------------- Update --------------------------- ----------------------------

That's why I was asking if your methods worked without problem because if they do not, other types of problems will arise that have nothing to do with the question, for example the error you have:

  

Caused by: java.lang.ClassCastException:   org.ksoap2.serialization.SoapPrimitive can not be cast   org.ksoap2.serialization.SoapObject

It's because you're receiving a String, so this is incorrect:

 SoapObject response = (SoapObject) envelope.getResponse();

must be:

SoapPrimitive response =  (SoapObject) envelope.getResponse();

I recommend you first try all the methods separately to ensure proper operation.

    
answered by 09.05.2016 / 20:20
source