I'm trying to get data by calling a web service, and for that I'm using an Async task class.
I want to use an “animated circle” while loading stuff (complete async task process). It will be really helpful if anyone can give me some idea how to do it.
I was looking at this answer by DBragion in Animated loading image in picasso, but doesn't explain exactly where to use those in the project.
Activity.java
       new AddressAsyncTask(getBaseContext(), new OnTaskCompletedObject() {
            @Override
            public void onTaskCompletedObject(JSONObject responseJson) {
                Constants.dataAddress = responseJson.toString();
                loaddata();
            }
        }).execute(email);
OnTaskCompletedObject.java
public interface OnTaskCompletedObject {
    void onTaskCompletedObject(JSONObject responseJson);
}
AddressAsyncTask.java
public class AddressAsyncTask extends AsyncTask<String, Integer, JSONObject> {
    private OnTaskCompletedObject listener;
    private JSONObject responseJson = null;
    private Context contxt;
    private Activity activity;
    String email;
    public AddressAsyncTask(Context context, OnTaskCompletedObject onTaskCompletedObject) {
        this.contxt = context;
        this.listener=onTaskCompletedObject;
    }
    // async task to accept string array from context array
    @Override
    protected JSONObject doInBackground(String... params) {
        String path = null;
        String response = null;
        HashMap<String, String> request = null;
        JSONObject requestJson = null;
        DefaultHttpClient httpClient = null;
        HttpPost httpPost = null;
        StringEntity requestString = null;
        ResponseHandler<String> responseHandler = null;
        // get the email and password
        Log.i("Email", params[0]);
        try {
            path = "http://xxxxxxxxxxxxxxxxx/MemberDetails";
            new URL(path);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            // set the API request
            request = new HashMap<String, String>();
            request.put(new String("Email"), params[0]);
            request.entrySet().iterator();
            // Store locations in JSON
            requestJson = new JSONObject(request);
            httpClient = new DefaultHttpClient();
            httpPost = new HttpPost(path);
            requestString = new StringEntity(requestJson.toString());
            // sets the post request as the resulting string
            httpPost.setEntity(requestString);
            httpPost.setHeader("Content-type", "application/json");
            // Handles the response
            responseHandler = new BasicResponseHandler();
            response = httpClient.execute(httpPost, responseHandler);
            responseJson = new JSONObject(response);
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        try {
            responseJson = new JSONObject(response);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        return responseJson;
    }
    @Override
    protected void onPostExecute(JSONObject result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        listener.onTaskCompletedObject(responseJson);
    }
}
 
     
    