android - Where should location be captured -


as many of may know, (default?) way request location updates calling code:

locationlistener locationlistener = new mylocationlistener();   locationmanager.requestlocationupdates(   locationmanager.gps_provider, 5000, 10, locationlistener); 

now, assume must receive location updates or long periods of time (even if app in background). implies that:

  1. one cannot 'tie' locationlistener activity because activity destroyed, locations no longer captured.
  2. the location manager cannot tied intentservice, because execute , finish right away.

my question: best place capture location updates long periods of time, when app in background?

service location updates continuously when app closed

public class gpsservice extends service{      private locationmanager locationmanager;     mylocationlistener locationlistenerp;     public gpsservice() {       }      @override     public ibinder onbind(intent intent) {         // todo auto-generated method stub         return null;     }     @override     public void oncreate() {          locationmanager = (locationmanager)                  getsystemservice(context.location_service);          locationlistenerp = new mylocationlistener();           locationmanager.requestlocationupdates(           locationmanager.gps_provider, 5000, 10, locationlistenerp);         }      @override     public void ondestroy() {         locationmanager.removeupdates(locationlistenerp);        }     @override     public void onstart(intent intent, int startid) {         toast.maketext(this, "location service started", toast.length_long).show();        }       public class mylocationlistener implements locationlistener {             @override             public void onlocationchanged(location location) {                 toast.maketext(getapplicationcontext(), "i here", toast.length_long).show();             }             @override             public void onproviderdisabled(string s) {             }             @override             public void onproviderenabled(string s) {                         }             @override             public void onstatuschanged(string arg0, int arg1, bundle arg2) {                 // todo auto-generated method stub              }         } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -