Set location for test from a scheduled task in android
<p>I am very new to Android (and mobile) programming.
I am trying to test my application by setting a GPS location every minute.
Trying to do that using a ScheduledExecutorService</p>

<p>So this is my runnable class:</p>

<pre><code>public class LocationTestScheduledTask implements Runnable {    
    private Activity activity;      
    public LocationTestScheduledTask(Activity a)
    {
        activity = a;
    }       
    @Override
    public void run() {
        LocationManager locationManager = 
            (LocationManager)activity.getSystemService(Context.LOCATION_SERVICE);
        locationManager.addTestProvider("Test", false, false, false, false, false, false, false, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
        locationManager.setTestProviderEnabled("Test", true);

        // Set up your test

        Location location = new Location("Test");
        Random rand = new Random();

        location.setLatitude(rand.nextDouble());
        location.setLongitude(rand.nextDouble());
        locationManager.setTestProviderLocation("Test", location);

        // Check if your listener reacted the right way

        locationManager.removeTestProvider("Test");         
    }     
}
</code></pre>

<p>In this is how i invoke the task from my activity.onCreate():</p>

<pre><code>final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
final Runnable locationTest = new LocationTestScheduledTask(this);
final ScheduledFuture sched=
        scheduler.scheduleAtFixedRate(locationTest , 10, 10, TimeUnit.SECONDS);
</code></pre>

<p>I am probably doing something very wrong here, since I don't see any location changes.</p>

<p>I have also tried to do something very similar with TimerTask, but no result there too.</p>

<p>Can anyone point me to whats wrong with the code?</p>
