Code example for ScheduledThreadPoolExecutor

0
public class LocationService extends Service implements
    LocationListener, Runnable {
  private static final int PERIOD_SECONDS=15;
  private LocationManager mgr=null;
  private ScheduledThreadPoolExecutor executor=
      new ScheduledThreadPoolExecutor(1);
  private boolean isScheduled=false;
 
  @Override 
  public void onCreate() { 
    super.onCreate(); 
 
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
 
    mgr=(LocationManager)getSystemService(LOCATION_SERVICE);
    mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    mgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                               this);
  } 
 
Experience pair programming with AI  Get Codota for Java