Java tutorial
package asynctasks; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import common.InterfaceClass; import common.JSONSerializer; import common.SessionUser; import fragments.SavePicker; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; import android.support.v4.app.FragmentManager; import android.widget.Toast; public class UpdateTicketDataAsync extends AsyncTask<String, Void, JSONObject> { private ProgressDialog pDialog; private JSONSerializer jSerial = new JSONSerializer(); private String updateticketUrl = "http://www.chumlychum.com/valet/valetapi/updateticket.php"; private Context context; private FragmentManager fm; public UpdateTicketDataAsync(Context context, FragmentManager fm) { this.context = context; this.fm = fm; } @Override protected JSONObject doInBackground(String... params) { SessionUser session = new SessionUser(context); HashMap<String, String> user = session.userDetails(); String staffentered = user.get("email"); List<NameValuePair> passer = new ArrayList<NameValuePair>(); passer.add(new BasicNameValuePair("tag", "updateticket")); passer.add(new BasicNameValuePair("tid", params[0])); passer.add(new BasicNameValuePair("ticket", params[1])); passer.add(new BasicNameValuePair("name", params[2])); passer.add(new BasicNameValuePair("cartype", params[3])); passer.add(new BasicNameValuePair("model", params[4])); passer.add(new BasicNameValuePair("color", params[5])); passer.add(new BasicNameValuePair("license", params[6])); passer.add(new BasicNameValuePair("park", params[7])); passer.add(new BasicNameValuePair("key", params[8])); passer.add(new BasicNameValuePair("staff", staffentered)); JSONObject json = jSerial.getJSONFromUrl(updateticketUrl, "POST", passer); return json; } @Override protected void onPreExecute() { pDialog = new ProgressDialog(context); pDialog.setMessage("Updating Ticket..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); } @Override protected void onPostExecute(JSONObject json) { pDialog.cancel(); int success; try { success = json.getInt("success"); if (success == 1) { SavePicker frag = (SavePicker) fm.findFragmentByTag("Save"); frag.iCcallback.updateTicket(true); frag.dialog.dismiss(); Toast.makeText(context, "Updated Woot", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, "ERROR IN SUBMISSION", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }