Skip to content

Instantly share code, notes, and snippets.

@pookie13
Created June 16, 2015 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pookie13/046e0f057ae9aa5352db to your computer and use it in GitHub Desktop.
Save pookie13/046e0f057ae9aa5352db to your computer and use it in GitHub Desktop.
AsyncTask Class to Call multiple service
import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;
import com.google.gson.Gson;
import com.hestabit.rqchat.connect.Connect;
import com.hestabit.rqchat.models.SignUp;
import org.apache.http.NameValuePair;
import org.json.JSONObject;
import java.io.Reader;
import java.util.List;
/**
* Created by piyus_000 on 6/15/2015.
*/
public class AsyncHelper extends AsyncTask<List<NameValuePair>,Void,JSONObject> {
Activity activity;
String methodName;
List<NameValuePair> params;
OnAsyncRequestComplete onAsyncRequestComplete;
public AsyncHelper(Activity activity, String methodName){
this.activity=activity;
this.methodName=methodName;
onAsyncRequestComplete=(OnAsyncRequestComplete)activity;
}
// Interface to be implemented by calling activity
public interface OnAsyncRequestComplete {
public void asyncResponse(JSONObject response);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(List<NameValuePair>... params) {
Connect connect = Connect.getInstance(activity);
Gson gson=new Gson();
JSONObject jsonObject = connect.getCorrectMethod(methodName, params[0]);
return jsonObject;
}
@Override
protected void onPostExecute(JSONObject jsonObject) {
super.onPostExecute(jsonObject);
onAsyncRequestComplete.asyncResponse(jsonObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment