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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -