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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:40+00:00 2026-05-23T03:57:40+00:00

I need to create an activity that starts a service that monitors the users

  • 0

I need to create an activity that starts a service that monitors the users position and when within a certain zone allow the calling Activity to update its view informing the user.

Since there are a few different ways to work with services I am a little confused to which of these is the correct one for my situation.

Use the startService() and stopService() methods: From what I understand I can’t directly talk back to the starting activity. In the google docs there is an example showing how to pass a BroadcastReceiver to the service via a PendingIntent and call it, but I don’t think that allow for me to update the running activity’s view…or will it?

Bound Service: From the docs it seems that this will allow for 2-way communication between the service and activity, but it was also mentioned that bound services don’t run in the background indefinitely. Now I don’t need, or even want, the service to run indefinitely, but in the worst case scenario I could need it to run in the bg for at least an hour or two without being killed.

Third (probably not so great) option: Run the location service in a thread in the activity, which will make real-time view updates easy, then in the onPause event, stop the location service in the activity and hand it off to a service via startService() and use the notification service to alert the user when a defined zone has been entered.

Any advice would be greatly appreciated.

  1. this says

    if you want the service to send a result back, then the client that starts the service can create a PendingIntent for a broadcast (with getBroadcast()) and deliver it to the service in the Intent that starts the service. The service can then use the broadcast to deliver a result.

  2. and this says

    A bound service typically lives only while it serves another application component and does not run in the background indefinitely.

  • 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-23T03:57:40+00:00Added an answer on May 23, 2026 at 3:57 am

    Ah, option (2) is probably what you want. You can override onStartCommand to return START_STICKY and the Service will continue to run after the Activity finishes.

    When you bindService you can get the actual Service instance back and then just invoke your custom methods on that as a way of communicating. Alternatively you could use one of the examples here

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

Sidebar

Related Questions

I'm trying to create a service that should be a singleton - I need
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create a backup of a SQL Server 2005 Database that's only
I need to create a batch file which starts multiple console applications in a
I need to create a button that has the same style as ButtonSpec with
So I have a very simple android activity that starts a timer when you
I'm writing an application that starts with a loading activity. In the loading activity
How can I create a custom activity that can be chosen by the user
I've a simple service that several of my activities need to access. The standard
When my activity is started it creates a service that acts as a server.

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.