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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:34:29+00:00 2026-05-18T04:34:29+00:00

I am making a application that uses the GPS receiver. The application will work

  • 0

I am making a application that uses the GPS receiver. The application will work on all versions starting from 1.6. I have a satellite Icon in which I tell the users the current status:

  • if icon is red – gps disabled
  • if icon is orange – gps is enabled and trying to fix on the satellites
  • if icon is green – gps is fixed and running fine.

After reading around here, I’ve found that some events for onLocationChanged trigger on 1.6 version but not later, so taking the advice I implemented a GPS listener. I have some really weird behavior as the status of the icon gets messed out. For instance I enable GPS and gets orange… after a fix get’s green.. after a few seconds gets read after a second orange and so on…

Here is the code I use. Please suggest what to change

public class TrackExecutionActivity extends Activity{

protected static final long GPS_UPDATE_TIME_INTERVAL=3000;  //millis
protected static final float GPS_UPDATE_DISTANCE_INTERVAL=0; //meters
private LocationManager mlocManager;
private MyGPSListener mGpsListener;
private LocationListener mlocListener; 

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.trackexecution);

        imgGpsState = (ImageView)findViewById(R.id.imgGpsState);
        mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocListener = new MyLocationListener();
        mGpsListener = new MyGPSListener();
}

private class MyGPSListener implements GpsStatus.Listener {
        public void onGpsStatusChanged(int event) {
            boolean isGPSFix = false;
            switch (event) {
                case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
                    if (mLastLocation != null)
                        isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_UPDATE_TIME_INTERVAL * 2;

                    if (isGPSFix) { // A fix has been acquired.
                        imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_green));
                    } else { // The fix has been lost.
                        imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_orange));
                    }

                    break;

                case GpsStatus.GPS_EVENT_FIRST_FIX:
                    imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_green));
                    break;
                case GpsStatus.GPS_EVENT_STARTED:
                    imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_orange));
                    break;
                case GpsStatus.GPS_EVENT_STOPPED:
                    imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_red));
                    break;
            }
        }
    }

public class MyLocationListener implements LocationListener
    {
        public void onLocationChanged(Location location)
        {
            if (location != null) {
                       mLastLocationMillis = SystemClock.elapsedRealtime();
            // do some things here
                     mLastLocation = location;

        }
        public void onProviderDisabled(String provider) 
        { 
            imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_red));
        } 

        public void onProviderEnabled(String provider) 
        { 
            imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_orange));
        } 

        //this doesn't trigger on Android 2.x users say
        public void onStatusChanged(String provider, int status, Bundle extras) 
        { 
        }
        }
        }

 @Override
    protected void onResume() {
     if(mlocManager != null) {
         if (mGpsListener == null)
         {
            mGpsListener = new MyGPSListener();
         }

         if (mlocListener == null)
         {
            mlocListener = new MyLocationListener();
         }

        mlocManager.addGpsStatusListener(mGpsListener);
        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_UPDATE_TIME_INTERVAL, GPS_UPDATE_DISTANCE_INTERVAL, mlocListener);
      }
       super.onResume();
    }
}
  • 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-18T04:34:30+00:00Added an answer on May 18, 2026 at 4:34 am

    change this:

    isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_UPDATE_TIME_INTERVAL * 2;
    

    your are setting a boolean with non boolean values.. hence the weird icon behavior during gps fixes you need to set that isGPSfix boolean somewhere.. for case of hasGPSfix or doesnothaveGPSfix..

    You might have meant:

    if ((SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_UPDATE_TIME_INTERVAL * 2) {
        isGPSFIX = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an application that does some custom image processing. The program will
I am developing a cocoa application that will be making heavy use of both
I'm making a Java application that uses the Slick library to load images. However,
Alright, I'm in the process of making a C# application that uses an API
Im making an application that uses of API-threads in C, The program takes N-files
I'm making a web based project management application using MySQL and PHP that uses
I'm making a WPF application that is comprised of Screens (Presenter + View). I
Where is a good place to start with making an application in .NET that
OK, say that my application is emitting (x86) instructions into memory, making the page
I'm making a php web application which stores user specific information that is not

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.