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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:04:07+00:00 2026-05-26T11:04:07+00:00

Situation: My program has parts that are heavily location based, but do to speed

  • 0

Situation: My program has parts that are heavily location based, but do to speed issues for when the location is actually needed, I don’t have time to lock. The solution I have designed is to get location information during primary operation (read: main screen) so that the location is available when the specific pieces need them.

Right now I register for updates and in onLocationChanged it checks if the location is accurate enough. If it is it calls removesUpdates.

Problem: If the device is somewhere that it can not get an accurate location (or any location) the GPS doesn’t shut off, the batters overheat, and the users get very upset.

Question: Is there a good clean way to check if the GPS is failing to get a lock, and tell it to give up at a certain point? I created a thread timer, but because the request is tied to onPause/onResume I do not want to create extra threads that may get all tangled up.

  • 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-26T11:04:07+00:00Added an answer on May 26, 2026 at 11:04 am

    Further to Merlin’s answer (I was just typing this lot out in notepad when it appeared) – I agree. My suggestion is:

    Facing a similar problem, I decided that the best thing to do would be to decouple the whole GPS from the main activity by means of a service.

    By this I mean have a service which does the requestsLocationUpdates() and removeLocationUpdates() and implements a LocationListener. This service provides methods which the main activity can call by means of an IBinder interface. It also sends broadcasts to the activity which implements a BroadcastReceiver to listen to these messages.

    So one of the the service methods your main activity could call would be (say)

    mLocnServ.startGPS(int timeout, float requiredAccuracy, int minUpdatePeriod, int minResendDistance)
    

    where mLocnServ is the binder interface exposed by the service.

    The last two arguments being those to pass as arguments to requestLocationUpdates in the service. (personally I don’t think these make any difference whatsoever to when the GPS turns itself off, as far as I can see it runs all the time until removeUpdates() is called). Anyway the first argument (timeout) should be the time you are prepared to wait for a fix of the required accuracy (argument 2).

    So in your service you will need a Runnable as a timer, which if it times out wil send a broadcast of type TIMED_OUT (say) and removeUpdates to stop the GPS. In your onLocationChanged you can test the location you get against the required accuracy and if good enough, send a broadcast of type GOT_A_FIX (say) and pass the location (lat/lon and accuracy) as extras in the broadcast, then removeUpdates to stop the GPS. (TIMED_OUT and GOT_A_FIX are just example names for enums which you can make up to distinguish between the broadcast message types)

    The main activity can decide what to do then in its BroadcastReceiver onReceive(), i.e whether to try again if it got a TIMED_OUT broadcast or what to do with the data it got from the GOT_A_FIX message.

    You’ll probably also need a mLocnServ.stopGPS in the binder so that you can shut the GPS no matter what the service is doing

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

Sidebar

Related Questions

I have a situation where I have a table that has a soft foreign
I have the following situation: There is a windows folder that has been mounted
We have a program that is used in one specific industry and has strings
This is the situation : I mostly program C# and have written types in
I have a situation where I want my program to read in some numbers
Hypothetical situation. I have a command line program in *nix (linux, BSD, etc.). It
I have following situation: String a = A Web crawler is a computer program
Here is my situation: I have program A which looks like this: Fmfile IF
I have a Python program that runs a series of experiments, with no data
Firstly, please don't dismiss this question - I'm aware it's an ugly situation but

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.