android - when I pressed create button application shuts down but at same time data gets stored in sql database 4 times -


/**          * creating product          * */         protected string doinbackground(string... args) {             string name = inputname.gettext().tostring();             string price = inputprice.gettext().tostring();             string description = inputdesc.gettext().tostring();              // building parameters             list<namevaluepair> params = new arraylist<namevaluepair>();             params.add(new basicnamevaluepair("name", name));             params.add(new basicnamevaluepair("price", price));             params.add(new basicnamevaluepair("description", description));              // getting json object             // note create product url accepts post method             jsonobject json = jsonparser.makehttprequest(url_create_product,                     "post", params);              // check log cat response             log.d("create response", json.tostring());              // check success tag             try {                 int success = json.getint(tag_success);                  if (success == 1) {                      // created product                     intent = new intent(getapplicationcontext(),                             allproductsactivity.class);                     startactivity(i);                      // closing screen                     finish();                 } else {                     // failed create product                 }             } catch (jsonexception e) {                 e.printstacktrace();             }              return null;         }          /**          * after completing background task dismiss progress dialog          * **/         protected void onpostexecute(string file_url) {             // dismiss dialog once done             pdialog.dismiss();         }      } } 

try 1 request , check working or not

public string request(string url, list<namevaluepair> namevaluepairs) {      try     {         httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost(url);         // httppost.setheader("encytype", "multipart/form-data");          httpparams httpparameters = new basichttpparams();         httpconnectionparams.setconnectiontimeout(httpparameters, timeoutconnection);         httpconnectionparams.setsotimeout(httpparameters, timeoutsocket);          urlencodedformentity entity = new urlencodedformentity(namevaluepairs, http.utf_8);         httppost.setentity(entity);          httpresponse httpresponse = httpclient.execute(httppost);          httpentity httpentity = httpresponse.getentity();         = httpentity.getcontent();      }     catch (unsupportedencodingexception e)     {         e.printstacktrace();     }     catch (clientprotocolexception e)     {         e.printstacktrace();     }     catch (ioexception e)     {         e.printstacktrace();     }      try     {          bufferedreader reader = new bufferedreader(new inputstreamreader(is, "iso-8859-1"), 8);         stringbuilder sb = new stringbuilder();         string line = null;         while ((line = reader.readline()) != null)         {             sb.append(line + "\n");         }         reader.close();         json = sb.tostring();     }     catch (exception e)     {         log.e("log_tag", "buffer error" + "error converting result " + e.tostring());     }      return json; } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -