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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:44:47+00:00 2026-06-07T16:44:47+00:00

Hello could somebody help me with what i’m doing wrong. I want this application

  • 0

Hello could somebody help me with what i’m doing wrong.

I want this application to work in the background, i just want to make in a button where to stop the locationmanager. when i use the removeUpdates, its not working. I cant call that function there.

public class LbsGeocodingActivity extends Activity {

private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 60000; // Minuten(van milliseconden) * aantal

protected LocationManager locationManager;
protected LocationListener locationListener;

protected Button retrieveLocationButton;
protected Button stopLocationButton;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button);
    stopLocationButton = (Button) findViewById(R.id.stop_location_button);


    LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);


    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            MINIMUM_TIME_BETWEEN_UPDATES, 
            MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            new MyLocationListener()
    );

    retrieveLocationButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showCurrentLocation();
        }
    }); 

    retrieveLocationButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
   LocationManager.removeUpdates(locationListener)  ;       }
    });      
} 


protected void showCurrentLocation() {

    Location location =    locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location != null) {
        String message = String.format(
                "Current Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        Toast.makeText(LbsGeocodingActivity.this, message,
                Toast.LENGTH_LONG).show();
    }

}   

public class MyLocationListener implements LocationListener {

    public void onLocationChanged(Location location) {
        String message = String.format(
                "New Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
    }

    public void onStatusChanged(String s, int i, Bundle b) {
        Toast.makeText(LbsGeocodingActivity.this, "Provider status changed",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderDisabled(String s) {
        Toast.makeText(LbsGeocodingActivity.this,
                "Provider disabled by the user. GPS turned off",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderEnabled(String s) {
        Toast.makeText(LbsGeocodingActivity.this,
                "Provider enabled by the user. GPS turned on",
                Toast.LENGTH_LONG).show();
    }

}

I really need this badly

  • 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-07T16:44:49+00:00Added an answer on June 7, 2026 at 4:44 pm

    Change the code from this (* indicates whats changed *):

    ***retrieveLocationButton***.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
        locationManager.removeUpdates(locationListener)  ;       
        }
    }); 
    

    To this:

    stopLocationButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            locationManager.removeUpdates(locationListener)  ;       
        }
    });   
    

    EDIT:

    use locationManager “the global variable which starts with small letter” and not LocationManager “the class which starts with capital letter” for the function removeUpdates()

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

Sidebar

Related Questions

Hello pls could someone help... I've tried everything to get this to work in
Hello could someone please help me with the following: I want to center the
Hello fellow Computer People! I could do this myself, but was just wondering if
Hello Could anyone help me update this snippent to iOS 4.2: -(void) whatever{ NSData
Hello could someone help me udnerstand how this code works ? go(Start,Dest,Route):- go0(Start,Dest,[],R), rev(R,Route).
Hello could someone help me udnerstand how this code works ? go(Start,Dest,Route):- go0(Start,Dest,[],R), rev(R,Route).
Hello could somebody tell me wath is wrong with my code. When i do
For example could I make it type something like Hello This Is A Test
Hello! I have a little problem I was hoping the community could help me
Hello fellow Grails Developers! I was wondering if you could help me with what

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.