android - Where to place function to fetch data from server when waiting for location data -
i'm building application has data server according latitude , longitude google play services location api. i'm not able figure out place functions location , fetch data server. i'm going explain me better. when application start have last known location , have seen possible through
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); currentgeolocation currentgeolocation = currentgeolocation.get(getactivity()); } @override public void onstart() { super.onstart(); mcurrentgeolocation.connectgoogleapiclient(); }
currentgeolocation
public static currentgeolocation get(context appcontext) { if (scurrentgeolocation == null) { scurrentgeolocation = new currentgeolocation(appcontext.getapplicationcontext()); } return scurrentgeolocation; } private currentgeolocation(context appcontext) { mappcontext = appcontext; mrequestinglocationupdates = true; // create pojo store last known location mcurrentgeolocationentity = new currentgeolocationentity(); buildgoogleapiclient(); createlocationrequest(); } @override public void onconnected(bundle bundle) { log.i(tag, "connected goggleapiclient"); if (mcurrentgeolocationentity.getmlastlocation() == null) { mcurrentgeolocationentity.setmlastlocation(locationservices.fusedlocationapi.getlastlocation(mgoogleapiclient)); } if (mrequestinglocationupdates) { startlocationupdates(); } }
my problem don't know place function retrieve data server. i'm using volley library , have written data. suggest?
if concerned visibility of fragment due not being loaded yet, can try 2 things. first using viewtreeobserver. use viewtreeobserver wait fragment or view finish loading fetch data. here example using view:
viewtreeobserver viewtreeobserver = view.getviewtreeobserver(); if (viewtreeobserver.isalive()) { viewtreeobserver.addongloballayoutlistener(new ongloballayoutlistener() { @override public void ongloballayout() { yourview.getviewtreeobserver().removeglobalonlayoutlistener(this); // fetch , data insert view here. ... } }); }
the next 1 can try fetching using runnable. example:
yourlayout = (relativelayout) findviewbyid(r.id.boxeslinearlayout); yourlayout .post(new runnable() { @override public void run() { // fetch , data insert view here. ... } });
Comments
Post a Comment