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 6232779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:10:42+00:00 2026-05-24T10:10:42+00:00

Attempting to get LocationUpdates in my Service, however, it doesnt ever seem to fire

  • 0

Attempting to get LocationUpdates in my Service, however, it doesnt ever seem to fire the LocationListener.

My Service starts a thread, which then loops with a Handler.postDelayed() – I originally used sleep(30000), however I thought this may have been preventing the locationUpdates. All the service does is launch this thread – and onStartCommand returns STICKY to keep it running:

public class TST extends Thread {

    final int DefaultNetworkTick = 120000; // 2 minutes
    final int DefaultLocationTick = 20000; //600000;  
    boolean CustomLocationUpdateTick = false; // If the network requests faster updates
    int CustomLocationUpdateTickMs = 600000; // Default 10 minutes

    public boolean kill = false;
    public Context context;

    Handler handler  = new Handler();

    Date nextNetworkReadTick;

    @Override
    public void run() {        
        Log.i("TST", "Start run() iteration");
        // Set the ticks to the appropriate values
        // Network gets read every 2 minutes

        nextNetworkReadTick = new Date();
        nextNetworkReadTick.setTime(nextNetworkReadTick.getTime() + DefaultNetworkTick);
        Log.i("TST", "Set next Network tick to " + nextNetworkReadTick.toString());
        Looper.prepare();
        Log.i("TST", "Performing location update setup...");
        SetupLocationListenerDefault();
        handler.postDelayed(runFunc, 2000);
        Looper.loop();
    }

    // We do our networking and stuff in here
    public Runnable runFunc = new Runnable(){
        public void run()
        {
            Log.i("TST", "run() iteration");

            if( new Date().after(nextNetworkReadTick) ) {
                // Set next tick
                nextNetworkReadTick = new Date();
                nextNetworkReadTick.setTime(nextNetworkReadTick.getTime() + DefaultNetworkTick);

                UpdateNetwork();
            }

            handler.postDelayed(runFunc, 1000);
        }
    };

    private void UpdateNetwork() {
            // TODO Auto-generated method stub
    }

    LocationManager locMgr;

    PendingIntent locationUpdateIntentPending;
    Intent locationUpdateIntent;

    LocationListener locationListener = new LocationListener()
    {
            @Override
            public void onLocationChanged(Location arg0) {
                    // TODO Auto-generated method stub
                    Log.i("TST", "OnLocationChanged: " + arg0.toString());
            }

            @Override
            public void onProviderDisabled(String provider) {
                    // TODO Auto-generated method stub
                    Log.i("TST", "OnProviderDisabled: " + provider);                
            }

            @Override
            public void onProviderEnabled(String provider) {
                    // TODO Auto-generated method stub
                    Log.i("TST", "OnProviderEnabled: " + provider);
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                    // TODO Auto-generated method stub
                    Log.i("TST", "OnStatusChanged");
            }

    };

    private void SetupLocationListenerDefault() {
        // Reset location manager
        if( locMgr != null ) {
                locMgr.removeUpdates(locationListener);
                locMgr = null;
        }

        locMgr = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = locMgr.getBestProvider(criteria, true);

        locMgr.requestLocationUpdates(provider, DefaultLocationTick, 0, locationListener);
    }

}
  • 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-24T10:10:43+00:00Added an answer on May 24, 2026 at 10:10 am

    Rebooted my phone and started getting updates – seems that Android had got stuck somewhere!

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

Sidebar

Related Questions

I am attempting to get the innerHTML of the next element, next to which
I am attempting to get a hidden form value which contains json, after the
I'm attempting to get started with MINA, and all of the examples seem to
I've been attempting to get a toy intent service running for monodroid essentially going
I am attempting to get a link to fire JQuery's .click() function so that
While attempting to get an old svn dump of a project under git control,
I'm attempting to get my first ASP.NET web page working on windows using Mono
I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the
I am attempting to get the information from one table (games) and count the
I have been attempting to get log4net logging in my asp.net web application with

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.