android - background service with data for later use best practice -


i'm writing application needs register actual location every minute, whether it's in foreground or background. when user decides it's time stop tracking, want gather data collected , use them.

to that, i've thought architecture tries save battery , tries efficient possible. i'm wondering if choice decent enough. here is:

  1. i start service s activity through startservice(). service construct data structure save data later use. communication between activity , service created through messenger objects.

  2. i register location updates managed receiver r. this:

    this.lm= (locationmanager) getsystemservice(location_service);         intent locationintent= new intent(getapplicationcontext(),travelposition.class); pendingintent locationpendingintent= pendingintent.getbroadcast(getapplicationcontext(), 0, locationintent, pendingintent.flag_update_current); lm.requestlocationupdates(locationmanager.network_provider, 7000, 1, locationpendingintent); 
  3. each time receiver r triggered, communicate service s. thinking startservice(intent) put coordinates in intent's extras.

  4. the service s store new data (my new location coordinates , other infos generate them) in inner data structure. should work whether app running in foreground or background

  5. once user stops tracking means of button in activity, latter communicate service data stored until then, calls stopservice

what think this? 1 more question: if user wants kill app, happens receiver? open app back?

first of all, right thinking architecture through before start writing code :)

second, recommend read following links:

http://developer.android.com/guide/topics/location/strategies.html http://devdiscoveries.wordpress.com/2010/02/04/android-use-location-services/

third, in case, don't need service s. can register receiver r , need in receiver r (including processing , saving data). in case, if exit application, still continue receive location updates.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -