gps - Getting location data on an Android device in certain intervals -


i trying make android app takes location data in intervals e.g:- 5 sec, 1 min,etc. here code :-

            public void onlocationchanged(location loc) {             // todo auto-generated method stub             if(loc!=null)             {                  //required interval               tinterval =(mininterval*60*1000) + (secinterval)*1000 - 1000;                //the app supports interval mode               radiobutton sel = (radiobutton) findviewbyid(mode.getcheckedradiobuttonid());                 //code manual functionality               if(sel.gettext().equals(manual_radio))               {                       time t = new time();                       t.settonow();                       db.addlocationattime(loc, t);                       toast.maketext(getapplicationcontext(), "location added database",toast.length_short).show();                               locate.removeupdates(this);                        b.settext(manual_button);                       d.setenabled(true);               }                //code interval functionality               else if(sel.gettext().equals(interval_radio))               {                               //count object of countdown class thread object                               if(count == null)                               {                                       //t time object                                       t.settonow();                                       //sqlitedatabase object logging location time                                       db.addlocationattime(loc, t);                                       toast.maketext(getapplicationcontext(), "location added database",toast.length_short).show();                                       count =  new countdown( tinterval);                                       count.start();                               }                                else if(count.getstate().tostring().equals("terminated"))                               {                                       t.settonow();                                       db.addlocationattime(loc, t);                                       toast.maketext(getapplicationcontext(), "location added database",toast.length_short).show();                                       count =  new countdown(tinterval);                                       count.start();                                                                 }                    }               }             } 

here code countdown class:- class used add interval app

public class countdown extends thread  {     long time;     public countdown(long duration)     {             time = duration;     }      public void run()     {                     long t1 = system.currenttimemillis();                     long t2 = 0;                                         {                       t2 = system.currenttimemillis();                           }while(t2 - t1 < time);                 } } 

the problem using above code not getting accurate intervals. getting 1 sec (due subtracted 1000 in formula) , 1 sec not happening always. can please tell me doing wrong ?

look @ locationmanager.requestlocationupdates, pass time interval in parameter..

locationmanager mlocationmanager = (locationmanager).getsystemservice(mactivity.location_service); mlocationmanager.requestlocationupdates(locationmanager.network_provider, 5000, 0, new geoupdatehandler()); 

Comments