php - Android App not syncing with database -
the andriod app i'm developing using http gets/posts using php files on website perform transactions on mysql database.
on php side, wrap data json parse on java end of app when receiving response. modified 1 of tables , eliminated unnecessary values table. when poll using php scripts website, polls correctly. when use app, uses same php script polling, returns additional values removed database.
i've restarted eclipse, cleaned project, , restarted android vdm refresh it; however, continues find values removed. ideas going on?
here php script i'm connecting app:
<?php mysql_connect("localhost", "******", "******"); mysql_select_db("bouncet2_pogoapp"); $query = "select * event_table order event asc"; $sql = mysql_query($query); while($row=mysql_fetch_assoc($sql)) $output[]=$row; print(json_encode($output)); mysql_close(); ?>
as code in app using script:
try { string response = customhttpclient.executehttpget("http://www.*****.com/****/****/***/getevents.php"); //system.out.println(response); try { eventarray = new jsonarray(response); //log.i(selecteventactivity.class.getname(), "number of entries " + eventarray.length()); m_adapterforspinner = new arrayadapter<string>(this, android.r.layout.simple_spinner_item); m_adapterforspinner.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); event_spinner.setadapter(m_adapterforspinner); (int = 0; < eventarray.length(); i++) { jsonobject jsonobject = eventarray.getjsonobject(i); m_adapterforspinner.add(jsonobject.getstring("event")); //log.i(addjumpersactivity.class.getname(), jsonobject.getstring("event")); } } catch (exception e) { e.printstacktrace(); } } catch (exception e) { e.printstacktrace(); }
the function executehttpget(url) part of class customhttpclient , follows:
public static string executehttpget(string url) throws exception { stringbuilder builder = new stringbuilder(); httpclient client = gethttpclient(); httpget request = new httpget(); request.seturi(new uri(url)); try { httpresponse response = client.execute(request); statusline statusline = response.getstatusline(); int statuscode = statusline.getstatuscode(); if (statuscode == 200) { log.i(customhttpclient.class.tostring(), "system status ok"); httpentity entity = response.getentity(); inputstream content = entity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(content)); string line; while ((line = reader.readline()) != null) { builder.append(line); } } else { log.e(customhttpclient.class.tostring(), "failed download file"); } } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return builder.tostring(); }
it looks response getting cached somewhere, ether in cache server between phone , server, or in phone itself.
if cache happening outside phone, adding appropriate headers disable caching trick. added headers of response server. there several ways this, think should work...
header("expires: tue, 03 jul 2001 06:00:00 gmt");
on phone side, depending on http client gethttpclient, client has caching turned on. in ice cream sandwich, google added caching httpurlconnection http client. caching has turned on according docs, many people seem have issues cache being on when unaware. i'm not familiar interworkings of various http clients on android, should start...
http://developer.android.com/reference/java/net/httpurlconnection.html
a quick , dirty check see if caching response add random, unused param url when calling server, like...
url += "?unused=" + uuid.randomuuid();
with in place, should not cached anywhere, can @ least determine if caching issue or else, , go there.
Comments
Post a Comment