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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:44:28+00:00 2026-05-27T16:44:28+00:00

When my application is quit my GPS sensor keeps working or when I change

  • 0

When my application is quit my GPS sensor keeps working or when I change activities my application crashes depending on my configuration (in the code below it crashes when I change activities or quit the application). How do I change my below activity so that when I quit the application the GPS sensor stops running but when I move to another activity it keeps running?

Here is the key parts to my activity:

public class InitialChoice extends Activity {
    LocationManager mlocManager;
    LocationListener mlocListener; 

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.initial_screen);

        mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocListener = new MyLocationListener();
        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    }

    @Override
    protected void onStop(){
        //mlocManager.removeUpdates(mlocListener); 

        mlocManager.removeGpsStatusListener((Listener) mlocListener);

        mlocManager = null;
    }
}

If I use the following code instead of onStop() the gps wont stop running:

@Override
public void finish(){
    //mlocManager.removeUpdates(mlocListener); 

    mlocListener = null;
    mlocManager = null;

}

LogCat:

12-16 21:54:58.120: D/LocationManager(909): requestLocationUpdates: provider = gps, listener = com.dummies.android.taskreminder.MyLocationListener@46284458
12-16 21:55:04.740: D/AndroidRuntime(909): Shutting down VM
12-16 21:55:04.740: W/dalvikvm(909): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
12-16 21:55:04.750: E/AndroidRuntime(909): FATAL EXCEPTION: main
12-16 21:55:04.750: E/AndroidRuntime(909): java.lang.RuntimeException: Unable to stop activity {com.dummies.android.taskreminder/com.dummies.android.taskreminder.activity.InitialChoice}: java.lang.ClassCastException: com.dummies.android.taskreminder.MyLocationListener
12-16 21:55:04.750: E/AndroidRuntime(909): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3632)
12-16 21:55:04.750: E/AndroidRuntime(909): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3677)
12-16 21:55:04.750: E/AndroidRuntime(909): at android.app.ActivityThread.access$2600(ActivityThread.java:135)
12-16 21:55:04.750: E/AndroidRuntime(909): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
12-16 21:55:04.750: E/AndroidRuntime(909): at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 21:55:04.750: E/AndroidRuntime(909): at android.os.Looper.loop(Looper.java:144)
12-16 21:55:04.750: E/AndroidRuntime(909): at android.app.ActivityThread.main(ActivityThread.java:4937)
12-16 21:55:04.750: E/AndroidRuntime(909): at java.lang.reflect.Method.invokeNative(Native Method)

New Errors for me with method from here: Stop Location Listener in Android

12-16 23:10:50.295: W/dalvikvm(1272): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
12-16 23:10:50.305: E/AndroidRuntime(1272): FATAL EXCEPTION: main
12-16 23:10:50.305: E/AndroidRuntime(1272): java.lang.RuntimeException: Unable to stop activity {com.dummies.android.taskreminder/com.dummies.android.taskreminder.activity.InitialChoice}: android.app.SuperNotCalledException: Activity {com.dummies.android.taskreminder/com.dummies.android.taskreminder.activity.InitialChoice} did not call through to super.onStop()
12-16 23:10:50.305: E/AndroidRuntime(1272): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3632)
12-16 23:10:50.305: E/AndroidRuntime(1272): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3677)

  • 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-27T16:44:28+00:00Added an answer on May 27, 2026 at 4:44 pm

    For now this seems to work reasonably well but there is probably a better way (background thread…..):

    @Override
    public void onDestroy(){
    mlocManager.removeUpdates(mlocListener);
    
        super.onDestroy();
    } 
    
    @Override
    public void onResume(){
    
        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
        super.onResume();
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Workbook_Open sub that does some stuff and then calls application.quit. However,
My problem is that the NSApplicationWillTerminateNotification is not called when I quit my application.
I need to add a quit-button to my application that runs from the menubar
I have the following code to listen firefox quit-application event observe: function(subject, topic, data)
I'm looking for a good way to tell my Cocoa application to quit itself.
Will it auto release when the user quit the application? or it will stay
When deploying the application to the device, the program will quit after a few
Application: WPF Application consisting of a textbox on top and a listbox below Users
How to make a Cocoa application quit when the main window is closed? Without
I want to quit application in Android. Just put a quit button, which kills

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.