Android. Use service or application class for locationListener -
i have task determine user location. can create locationlistener in application class. or can use service.
locationmanager locationmanager=(locationmanager)this.getsystemservice(context.location_service); locationlistener locationlistener=new locationlistener(){ public void onlocationchanged( location location){ dive.setlongitude(location.getlongitude()); dive.setlatitude(location.getlatitude()); maphelper.setmapposition(dive.getlatitude(),dive.getlongitude()); } public void onstatuschanged( string provider, int status, bundle extras){ } public void onproviderenabled( string provider){ } public void onproviderdisabled( string provider){ }}; locationmanager.requestlocationupdates( locationmanager.network_provider,0,0,locationlistener); locationmanager.requestlocationupdates( locationmanager.gps_provider,0,0,locationlistener);
what need use task? service or application class? advantages , disadvantages of service? advantages , disadvantages of application class?
you'd never, ever use application. might use activity. using activity more convenient, can't persist next activity. service requires boilerplate , less ease of access data, can used multiple activities need data.
Comments
Post a Comment