3

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()

Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189

4 Answers4

4
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]);
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
2

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]);
TheFlash
  • 5,997
  • 4
  • 41
  • 46
0

You can also pass in an array of strings so:

new String[] info = ...
soap_object.execute(info);
user2483079
  • 533
  • 2
  • 10
0

You can also use Parameterobjects, see this thread, answer of David Wasser: How can you pass multiple primitive parameters to AsyncTask?

Community
  • 1
  • 1
bish
  • 3,381
  • 9
  • 48
  • 69