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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:32:34+00:00 2026-06-08T13:32:34+00:00

I have an app working that is GPS based. It has many activities and

  • 0

I have an app working that is GPS based. It has many activities and all use the GPS. For example, one activity shows the distance to a location, another shows the speed and direction. I set up and call requestLocationUpdates() in onCreate() and call removeUpdates() in onPause().

This all works but the GPS blinks and has to re-acquire when switching activities. I did a test and if I put the removeUpdates() in onStop() instead of in onPause() there is no blinking. Apparently onStop() is called after the new activity starts which explains the lack of blinking.

I have read the posts on this subject and there seems to be a difference of opinion. However, it looks like I should use onStop() and am wondering if there is any reason I should not.

The second issue is that there is no onResume() code so there is no GPS after a back-arrow or after turning the screen off and on. I should fix this. Right now my onCreate() code creates the location manager and basically has all my code in it. It looks like following the life cycle flow chart that I should move the removeUpdates() to onStop and move the creation of the lm and ll to onStart(). Is this correct?

Here is my onCreate() code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.set);
    textView1 = (TextView)findViewById(R.id.textView1);
    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    ll = new mylocationlistener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}

Here is my onPause code:

    @Override
    protected void onPause() {
        super.onPause();
        if(lm != null) {
            lm.removeUpdates(ll);
        }
        ll = null;
        lm = null;
    }

So I think I should just change the onPause() to onStop() and make onStart() this:

@Override
public void onStart() {
    super.onStart();
    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    ll = new mylocationlistener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}

And my onCreate code as this;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.set);
    textView1 = (TextView)findViewById(R.id.textView1);
  }

This said, I am kind of new to all this and this is my first application so I would like to know what I am missing here.

  • 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-08T13:32:37+00:00Added an answer on June 8, 2026 at 1:32 pm

    I’ve done something similar to your app, except that I’ve delegated the GPS functionality to a service which stops the GPS when no activities are bound to it and starts it when an activity binds to it. I bind to the service in the onStarts and unbind in the onStops. Logging the on.. methods when I switch activities gives a sequence like this:

    FIRST Activity onCreate
    FIRST Activity onStart
    FIRST Activity onResume
    FIRST Activity onPause
    SECOND Activity onCreate
    SECOND Activity onStart
    SECOND Activity onResume
    FIRST Activity onStop
    

    If done it via a service so that I’ve only got one LocationManager to control, you could either take the same approach, or requestUpdates in the onStarts() and remove them in the onStops()

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

Sidebar

Related Questions

I have a fantasy football league rails app that was working last year and
I have an Android app that I had working a few months ago which
I have a jqueryMobile app that uses google maps api and is working properly
I'm working on an app that will hopefully have the ability to block incoming
I'm working on an app (Written in C#) that have a setting to run
I have been working with a Windows Mobile 6 app that is built with
We've put together an app that is mostly working in phonegap. We have an
This part of an app that I am working on, I have the following
I'm working with a WinForms app. I have an RDLC report that will be
I am working on a app in CI, I have a model that inserts

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.