Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass parameter to AsyncTask<String, Void, Void>

I am build android app which is supposed to open barcode scanner screen and scan the barcode, then send the barcode string to a webservice. I have done barcode reading part, sending static strings to webservice. I am sending strings to webservice asynchronously.

here is my code

public class AsyncCallWS extends AsyncTask<String, Void, Void> {
    @Override
    protected Void doInBackground(String... params) {
        try {
            execute__barcode_webservice();
        } catch (Exception e) {
            // TODO: handle exception
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

    }

    @Override
    protected void onPreExecute() {

    }

    @Override
    protected void onProgressUpdate(Void... values) {

    }
}

I need to pass two string to "execute__barcode_webservice()"

This is how I call asynctask to send strings.

 AsyncCallWS soap_object = x.new AsyncCallWS();
 soap_object.execute();

How do I pass two strings to soap_object and then to execute__barcode_webservice()

like image 546
Arif YILMAZ Avatar asked Dec 09 '25 23:12

Arif YILMAZ


2 Answers

soap_object.execute(new String []{"StringOne","StringTwo"});

You can also do :

soap_object.execute("StringOne","StringTwo");

In doInBackground, params is a varargs argument, so just do :

execute__barcode_webservice(params[0], params[1]);
like image 145
Alexis C. Avatar answered Dec 12 '25 12:12

Alexis C.


Try this..

AsyncCallWS soap_object = x.new AsyncCallWS();

soap_object.execute(new String []{"String_one","String_two"});

Then in doInBackground

 execute__barcode_webservice(params[0],params[1]);
like image 38
TheFlash Avatar answered Dec 12 '25 13:12

TheFlash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!