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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:49:23+00:00 2026-05-19T12:49:23+00:00

In my App I have a broadcast receiver that upon receiving a keyword in

  • 0

In my App I have a broadcast receiver that upon receiving a keyword in an SMS message, it starts a service that tracks the GPS location of the phone. I do this using –

context.startService(new Intent(context,TrackGPS.class));

I also need to be able to stop the service upon receiving another keyword in an SMS message, I have tried to do this but the GPS sensor still tracks the location and GPS icon flashes at the top of the screen. I tried to do this using –

context.stopService(new Intent(context, TrackGPS.class));

I figure this might be because the GPS listener needs to be unregistered. Can anyone help me in getting this service to stop + stop the GPS tracking upon receipt of a text? Thanks in advance.

Solution

@Override
public int onStartCommand(Intent GPSService, int flags, int startId) {
    boolean startListening = GPSService.getExtras().getBoolean("IsStartTracking");
    if (startListening == true){
        lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }
    else {
        lm.removeUpdates(this); 
        stopSelf();
    }
    return 1;
}
  • 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-19T12:49:24+00:00Added an answer on May 19, 2026 at 12:49 pm

    I don’t think your issue is stopping the service. By killing your service you are not killing the LocationListener object that is still looking for updates.

    I would do the following.

    Instead of stopping and starting your services, simply start your service every time you need to do something (Start listening or stop listening).

    Add an extra to the Intent you use to tell you what you want to do, something like:

    Intent GPSService = new Intent(context, TrackGPS.class);
    GPSService.putExtra("IsStartTracking", true);
    context.startService(GPSService);   
    

    In your onStart method override of your service, you can now register and unregister location listeners on a single instance of your LocationManager based on the value of “IsStartTracking”

    boolean startListening = intent.getExtras().getBoolean("IsStartTracking");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I have a broadcast receiver that turns on GPS upon receiving
I have a broadcast receiver that starts a service when the device is finished
I have an app that has one Broadcast Receiver that listens for a specific
I have an application that starts on boot using a broadcast receiver, also I
Hello I faced the same problem I have 1 broadcast receiver from that I
I have an app that listens for incoming calls and depending upon the number
Ok, so I have an app that needs to receive incoming SMS, and send
I have a service in the background that starts on phone boot, and displays
I have a broadcast receiver that on boot of the phone runs a pending
I am trying to create an SMS broadcast receiver that will execute whenever a

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.