php - Unable to start service with Intent { flg=0x4 (has extras) } -
i want insert php service. i've got error :
unable start service skripsi.ubm.studenttracking.altitudesurvey@366d624d intent { flg=0x4 cmp=skripsi.ubm.studenttracking/.altitudesurvey (has extras) }: android.os.networkonmainthreadexception
this code :
public void insert() { string time; simpledateformat dayformat = new simpledateformat("hh:mm:ss", locale.us); calendar calendars = calendar.getinstance(); time = dayformat.format(calendars.gettime()); try { httpclient = new defaulthttpclient(); httppost = new httppost("http://studentstracking.hol.es/altitudesurvey.php"); namevaluepairs = new arraylist<namevaluepair>(2); namevaluepairs.add(new basicnamevaluepair("baro", value)); namevaluepairs.add(new basicnamevaluepair("jam", time)); httppost.setentity(new urlencodedformentity(namevaluepairs)); response = httpclient.execute(httppost); responsehandler<string> responsehandler = new basicresponsehandler(); final string response = httpclient.execute(httppost, responsehandler); toast.maketext(altitudesurvey.this, "response server : " + response, toast.length_short).show(); if (response.equalsignorecase("success")) { toast.maketext(getapplicationcontext(), "data has been inserted", toast.length_short).show(); } else { toast.maketext(getapplicationcontext(), "data failed", toast.length_short).show(); } } catch (clientprotocolexception e) { e.printstacktrace(); } catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } }
this method inside service. me how resolve ?
you facing android.os.networkonmainthreadexception
means calling insert() method oncreate . need use asynctask
save exception.
private class downloadfilestask extends asynctask<url, integer, long> { protected long doinbackground(url... urls) { insert() return result; } protected void onprogressupdate(integer... progress) { } protected void onpostexecute(long result) { } }
start asynctask
new downloadfilestask().execute();
Comments
Post a Comment