Android: onResume() crashes on HttpRequest to Google Places -
before making httprequest
google places, need check connection.
if there no active connection, display "no connection" user, otherwise current location , perform request.
some test cases:
a) 1. enable connection -> gets info fine, 2. 1 time again -> gets info fine
b) 1. no connection -> "no connection", 2. enable connection -> gets info fine
c) 1. enable connection -> gets info fine, 2. disable connection -> "no connection"
good far, then
d) 1. active connection -> gets info fine, 2. disable connection -> "no connection", 3. enable connection -> "write error: ssl=0x5a90fbb0: i/o error during scheme call, broken pipe"
i have log statements confirming location info right before httprequest
in 3rd step of test case d). cannot see reason why failing.
code requested:
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.results); // set location manager work location service locationmanager = (locationmanager) getsystemservice(context.location_service); if (checkinternet()) { currentlocation = locationmanager .getlastknownlocation(locationmanager.network_provider); location = currentlocation.getlatitude() + "," + currentlocation.getlongitude(); places = new placelist(); // keyword passed in previous activity intent intent = this.getintent(); keyword = intent.getstringextra("keyword"); if (keyword != "") { class googlerequest extends asynctask<void, void, integer> { protected integer doinbackground(void... params) { mht = myhttptransport.createrequestfactory(); resources res = getresources(); seek { httprequest request = mht .buildgetrequest(new genericurl( res.getstring(r.string.places_search_url))); request.geturl().put("key", res.getstring(r.string.google_places_key)); request.geturl().put("location", location); request.geturl().put("radius", config.radius); request.geturl().put("keyword", keyword); request.geturl().put("sensor", false); places = request.execute().parseas( placelist.class); } grab (ioexception e) { log.e(config.msgtag, e.getmessage()); } homecoming null; } @override protected void onpostexecute(integer result) { // details omitted because fails // info places field } } @override protected void onresume() { super.onresume(); locationmanager.requestlocationupdates( locationmanager.network_provider, 5000, 100, this); } @override protected void onpause() { super.onpause(); locationmanager.removeupdates(this); } @override public void onlocationchanged(location location) { locationmanager.removeupdates(this); currentlocation = location; } public boolean checkinternet() { connectivitymanager cm = (connectivitymanager) .getsystemservice(context.connectivity_service); networkinfo wifi = cm.getnetworkinfo(connectivitymanager.type_wifi); networkinfo mobile = cm .getnetworkinfo(connectivitymanager.type_mobile); if (wifi.isconnected()) { homecoming true; } else if (mobile.isconnected()) { homecoming true; } homecoming false; } }
log:
02-15 19:34:32.582: e/*(9967): write error: ssl=0x5efd0a98: i/o error during scheme call, broken pipe
the rest of log postexecute() that's irrelevant.
i have solved problem.
in custom httptransport
class, have final
apachehttptransport
object, gets re-used every time createrequestfactory()
method called. problem seems when connection lost, , new connection created, tries utilize old 1 (something along lines). around this, create new apachehttptransport
object within createrequestfactory()
method.
android httprequest onresume google-places
No comments:
Post a Comment