Athan
Athan

Reputation: 3

android ksoap2 response issue

I have an android application that calls a web service various times throughout the application. Since calling the ksoap2 method makes the application not-responsive, I had to put the whole thing into AsyncTask class.

All I did is make a ProgressDialog appear on onPreExecute(), and the call to the web service on doInBackground, as done in my main program. However, although the call to the web service works, the response from the web service is "com.SmartInfinity.InfinityMain$webServiceCall@40697618". FYI com.SmartInfinity is my app package, InfinityMain is my main activity, and webServiceCall is the method that calls the web service.

Does anyone have any idea why this is happening? The web service is supposed to return results as "[field_x1=value_x1;field_y1=value+y1; field_x2=value_x2;field_y2=value_y2;]" When I call the same function with the same arguments outside the AsyncTask it works perfectly.

Thanks for your help.

Edit: here is my code:

private class webServiceCall extends AsyncTask<String, Void, Object> 
{
    @Override
    protected void onPreExecute()
    {
        dialog.show();
    }

    protected Object onPostExecute(Object... params) 
    {
        dialog.dismiss();
        return params;
    }

    @Override
    protected Object doInBackground(String... params) 
    {
        Object result = null;
        String[] temp = new String[params.length - 2];
        String method_name = params[0];
        String action_name = params[1];
        for (int i = 2; i < params.length; i++)
        {
            temp[i-2] = params[i];
        }
        result = callWebService(method_name, action_name, temp, 60);
        dialog.dismiss();
        return result;
    }

}

The result is then converted to a string and used normally. Here is how I call the AsyncTask and process my result:

Object result = new webServiceCall().execute(UserArgs);


        String str = result.toString();
        String delims = "[=;]+";
        String [] stringuser = str.split(delims);

Upvotes: 0

Views: 494

Answers (1)

Tobias
Tobias

Reputation: 883

Object result = new webServiceCall().execute(UserArgs);

That is your problem. The new webServiceCall().execute(UserArgs); doesn't return the result of your asyncTask it only returns an reference to your task. The result of your callWebService is sent to onPostExecute(). It is here you can use the result. Either call a callback from here or you can use the result directly (here you are back in the UI-thread so you can modify the UI here).

Upvotes: 1

Related Questions