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

  • Home
  • SEARCH
  • 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 6652169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:06:11+00:00 2026-05-26T01:06:11+00:00

My Android app has two location listeners, one for fine and one for coarse

  • 0

My Android app has two location listeners, one for fine and one for coarse listening. I want to be able to detect when the user turns their location services off and on.

Whenever I turn my phones GPS or network location services OFF the onProviderDisabled method is called as expected. When I turn GPS or network services ON the onProviderEnabled is never called!

I have put the code for one of the listeners below….

Update…

I have discovered that the problem is related to unregistering the listeners in onPause. When I remove the code “locationManager.removeUpdates(myFineLocationListener);” the onProviderEnabled() method IS called.

Perhaps the act of disabling the (say) GPS automatically unregisters the listener? Perhaps I should unregister thje listener in onDestroy rather than onPause() ???

PS. Maybe it is relevant that I mention that my activity has a button that goes directly to the devices location settings page. It acts as a shortcut. I use this shortcut to disable/enable location services then use the Back button to return to my app. I will put the code for this button at the very end of this post.

Code:

(The createLocListeners() method is called from onCreate();)

 void createLocListeners() {

        //if null, create a new listener
        //myFineLocationListener is a class variable     
        if (myFineLocationListener == null) {

        //Listen for FINE location updates   
                myFineLocationListener = new LocationListener(){

                    @Override
                    public void onLocationChanged(Location location) {
                        //Do something
                    }

                    @Override
                    public void onProviderDisabled(String provider) {   
                                 //This gets called when I change location settings (eg GPS on or off)  on the phone            }



                                  @Override
                           public void onProviderEnabled(String provider) {
                                  //This DOES NOT get called when I change location settings (eg GPS on or off)  on the phone   
                           }

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {   
                    }

                };  //end on location listener
        } //end if fine listener is null

    } //end createLocListener() function






    @Override
    protected void onResume() {
        super.onResume();

        //REGISTER LOCATION LISTENERS
        try {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LISTENING_INTERVAL, LISTENING_DISTANCE, myFineLocationListener);
        } 
        catch (IllegalArgumentException e){
        //Tried catching exceptions but there weren't any
        }         
        catch (RuntimeException e) {            
        }





    }// end onResume()




    @Override     
        protected void onPause() {         
        super.onPause();        

        //UNREGISTER LOCATION LISTENERS
        locationManager.removeUpdates(myFineLocationListener);

    } //end onPause

Similar problem: Location service onProviderEnabled never called

Code for button that opens the location Settings page…

        //JUMP TO LOCATION SERVICES SETTINGS
    ibLoc.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }

    }); //end jump to location services button listener
  • 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-26T01:06:12+00:00Added an answer on May 26, 2026 at 1:06 am

    IMO, when you go to settings the onPause() is called and listeners are unregistered. Then you enable the GPS and return to your activity. So when you register the listeners the GPS is already enabled, so listener onProviderEnabled() is never called, since it is only called when GPS status is changed to enabled.

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

Sidebar

Related Questions

My Android app has two Spinners (dropdown menus) working fine. However, now I've added
I want to make an android application which has two tap in one view
My android app has a two word app name, and the 2nd word doesn't
I've got an Android app which has a periodic background Service. I want this
I've got some XML resources in my Android app. Each one has a different
I have an app that has two buttons – one for email & one
Hi Ive written a simple android application with two xml pages, one has an
I've created a custom button in my Android app that has basically two different
If I have understood correctly, an android process has two heaps - one managed
My android app currently has two layouts for its splash screen, portrait and landscape.

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.