Created
June 16, 2015 08:23
-
-
Save pookie13/046e0f057ae9aa5352db to your computer and use it in GitHub Desktop.
AsyncTask Class to Call multiple service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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