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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:02:02+00:00 2026-06-13T15:02:02+00:00

I am using Network Location provider. I need to call onLocationChanged method from my

  • 0

I am using Network Location provider.
I need to call onLocationChanged method from my LocationListener only once per 1 hour.
Here is my code:

MyLocationListener locationListener = new MyLocationListener();   
locationMangaer.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3600000, 0,locationListener);

But it doesn’t work. My onLocationChanged calling very often.

What parameters must I use?

  • 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-06-13T15:02:03+00:00Added an answer on June 13, 2026 at 3:02 pm

    From the LocationManager#requestLocationUpdates() documentation:

    Prior to Jellybean, the minTime parameter was only a hint, and some location provider implementations ignored it. From Jellybean and onwards it is mandatory for Android compatible devices to observe both the minTime and minDistance parameters.

    However you can use requestSingleUpdate() with a Looper and Handler to run the updates once an hour.


    Addition
    To start you can read more about Loopers and Handlers here.

    You are using API 8 which is a good choice, but this limits which LocationManager methods we can call since most were introduced in API 9. API 8 only have these three methods:

    requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)
    requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener, Looper looper)
    requestLocationUpdates(String provider, long minTime, float minDistance, PendingIntent intent)
    

    Let’s use the first method, it is the simplest.

    First, create your LocationManager and LocationListener as you normally would, but in onLocationChanged() stop requesting more updates:

    @Override
    public void onLocationChanged(Location location) {
        mLocationManager.removeUpdates(mLocationListener);
        // Use this one location however you please
    }
    

    Second, create a couple new class variables:

    private Handler mHandler = new Handler();
    private Runnable onRequestLocation = new Runnable() {
        @Override
        public void run() {
            // Ask for a location
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
            // Run this again in an hour
            mHandler.postDelayed(onRequestLocation, DateUtils.HOUR_IN_MILLIS);
        }
    };
    

    Of course, you ought to disable all of your callbacks in onPause() and enable them again in onResume() to prevent the LocationManager from wasting resources by acquiring unused updates in the background.


    A more technical point:
    If you are concerned about blocking the UI thread with the LocationManager, then you can use the second requestLocationUpdates() method to supply a specific Looper from a new Thread (say a HandlerThread).

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

Sidebar

Related Questions

I have implemented Location Based Services using Network Location Provider it doesn't providing me
I am using cwac-Location Poller (from here ) to constantly poll user location and
I am trying to call a webservice hosted on the local network using https
Using graphs in network x i can call the following attributes for node n
Hi am trying get GPS using network provider and GPS provider. but am getting
Hi, I am trying to get the gps location using location provider and gps
I'm using SQLite so it's only a file, not a server, but here's the
I have an android application using LocationManager get the cell network location and not
My app should find the current location using GPS , Cellular network or WiFi
I am trying to get current location using GPS , Cellular Network or WiFi

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.