Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:05:54+00:00 2026-05-25T06:05:54+00:00

I am very new to Android (and mobile) programming. I am trying to test

  • 0

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

So this is my runnable class:

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");         
    }     
}

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

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

I am probably doing something very wrong here, since I don’t see any location changes.

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

Can anyone point me to whats wrong with the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:05:54+00:00Added an answer on May 25, 2026 at 6:05 am

    You could use a handler. I’d say it would make things a lot easier:

    Handler handler = new Handler();
    Runnable locationTest = new LocationTestScheduledTask(this);
    
    handler.postDelayed(locationTest, 1000*60); // 1000 miliseconds * 60 miliseconds = 1 minute
    

    you would put the handler.postDelayed(...) in your onCreate as well as in your class body if you want to change the location every minute.

    Something easier that you could do would be to run your app on an Emulator, then go to DDMS in Eclipse, then you can send the device gps latitude and longitude coordinates.

    You can see where to send the coordinates in th image below:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Android. I'm thinking about creating an application that uses multiple
I am very new to Android Development. I am trying a sample application and
I'm very new to Android programming and I've been trying to figure out why
I'm very new to Android programming, so this is probably something pretty basic. I
I am very new to Android. I am trying to build inflate a context
I am very new to android development and have been trying to draw a
I'm very new to programming in Android, but have been struggling all day with
Very new to Android development, and I am importing a bitmap that is 799
Am very new to Android programming, so sorry if this is a simple problem.
I am very new to Android application development. Just started Hello world android application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.